aboutsummaryrefslogtreecommitdiff
path: root/.local/bin/setwall
blob: a7f05535d7c9c29a001bc390addca1151c61b620 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/bin/bash
WALL_DIR="$HOME/pix/wallpapers/catppuccin/"
MODE="random"
CUSTOM_PATH=""

apply_wallpaper() {
    # Apply wallpaper
    if ! pgrep -x hyprpaper >/dev/null; then
        # Hyprpaper not running → start with chosen wallpaper
        cat > ~/.config/hypr/hyprpaper.conf <<EOF
wallpaper {
    monitor =
    path = $NEW_WALL
}
EOF
hyprpaper &
wal -i $NEW_WALL -n
else
    # Hyprpaper is running → change it live
    cat > ~/.config/hypr/hyprpaper.conf <<EOF
wallpaper {
    monitor =
    path = $NEW_WALL
}
EOF
    hyprctl hyprpaper wallpaper ",$NEW_WALL"
    wal -i $NEW_WALL -n
    fi

}

# Parse options
while getopts ":mnp:" opt; do
    case $opt in
        m) MODE="menu" ;;
        p) MODE="path"; CUSTOM_PATH="$(realpath $OPTARG)" ;;
        n) MODE="nc" ;;
        \?) echo "Usage: $0 [-m] [-p /path/to/image] [-n]" >&2; exit 1 ;;
        :) echo "Option -$OPTARG requires an argument." >&2; exit 1 ;;
    esac
done

# Choose wallpaper
case $MODE in
    random)
        NEW_WALL=$(find "$WALL_DIR" -type f | shuf -n 1)
        if [[ -z "$NEW_WALL" ]]; then
            NEW_WALL="$HOME/.config/hypr/default-wallpaper.png"
        fi
        apply_wallpaper
        ;;
    path)
        if [[ -f "$CUSTOM_PATH" ]]; then
            NEW_WALL="$CUSTOM_PATH"
        else
            echo "Error: File not found -> $CUSTOM_PATH" >&2
            exit 1
        fi
        apply_wallpaper
        ;;
    menu)
        NEW_WALL=$(nsxiv -tfpo $WALL_DIR)
        apply_wallpaper
        ;;
    nc)
        echo "Not changing anything"
        pgrep 'hyprpaper' || hyprpaper &
        ;;
esac