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