| 1 | #!/bin/bash |
| 2 | WALL_DIR="$HOME/pix/wallpapers/catppuccin/" |
| 3 | MODE="random" |
| 4 | CUSTOM_PATH="" |
| 5 | |
| 6 | apply_wallpaper() { |
| 7 | # Apply wallpaper |
| 8 | if ! pgrep -x hyprpaper >/dev/null; then |
| 9 | # Hyprpaper not running → start with chosen wallpaper |
| 10 | cat > ~/.config/hypr/hyprpaper.conf <<EOF |
| 11 | preload = $NEW_WALL |
| 12 | wallpaper = ,$NEW_WALL |
| 13 | EOF |
| 14 | hyprpaper & |
| 15 | wal -i $NEW_WALL -n |
| 16 | else |
| 17 | # Hyprpaper is running → change it live |
| 18 | cat > ~/.config/hypr/hyprpaper.conf <<EOF |
| 19 | preload = $NEW_WALL |
| 20 | wallpaper = ,$NEW_WALL |
| 21 | EOF |
| 22 | hyprctl hyprpaper preload "$NEW_WALL" |
| 23 | hyprctl hyprpaper wallpaper ",$NEW_WALL" |
| 24 | wal -i $NEW_WALL -n |
| 25 | fi |
| 26 | |
| 27 | } |
| 28 | |
| 29 | # Parse options |
| 30 | while getopts ":mnp:" opt; do |
| 31 | case $opt in |
| 32 | m) MODE="menu" ;; |
| 33 | p) MODE="path"; CUSTOM_PATH="$(realpath $OPTARG)" ;; |
| 34 | n) MODE="nc" ;; |
| 35 | \?) echo "Usage: $0 [-m] [-p /path/to/image] [-n]" >&2; exit 1 ;; |
| 36 | :) echo "Option -$OPTARG requires an argument." >&2; exit 1 ;; |
| 37 | esac |
| 38 | done |
| 39 | |
| 40 | # Choose wallpaper |
| 41 | case $MODE in |
| 42 | random) |
| 43 | NEW_WALL=$(find "$WALL_DIR" -type f | shuf -n 1) |
| 44 | if [[ -z "$NEW_WALL" ]]; then |
| 45 | NEW_WALL="$HOME/.config/hypr/default-wallpaper.png" |
| 46 | fi |
| 47 | apply_wallpaper |
| 48 | ;; |
| 49 | path) |
| 50 | if [[ -f "$CUSTOM_PATH" ]]; then |
| 51 | NEW_WALL="$CUSTOM_PATH" |
| 52 | else |
| 53 | echo "Error: File not found -> $CUSTOM_PATH" >&2 |
| 54 | exit 1 |
| 55 | fi |
| 56 | apply_wallpaper |
| 57 | ;; |
| 58 | menu) |
| 59 | NEW_WALL=$(nsxiv -tfpo $WALL_DIR) |
| 60 | apply_wallpaper |
| 61 | ;; |
| 62 | nc) |
| 63 | echo "Not changing anything" |
| 64 | pgrep 'hyprpaper' || hyprpaper & |
| 65 | ;; |
| 66 | esac |