-
Notifications
You must be signed in to change notification settings - Fork 0
/
wallpaper
executable file
·80 lines (62 loc) · 1.56 KB
/
wallpaper
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
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/env sh
set -euo pipefail
WALLPAPERS_DIR="$XDG_DATA_HOME/wallpapers/"
main() {
if [ "$#" -eq 0 ]; then
help
exit
fi
case "$1" in
'-l' | '--load')
feh --no-fehbg --bg-scale "$WALLPAPERS_DIR/current"
;;
'-p' | '--pick')
pick
;;
'-r' | '--random')
random
;;
'-h' | '--help')
help
;;
esac
}
pick() {
wallpapers="$(get_available_wallpapers)"
wallpapers_count="$(echo "$wallpapers" | wc -l)"
[ "$wallpapers_count" -gt 0 ] || exit 1
chosen_wallpaper="$(echo "$wallpapers" | nsxiv -ito | head -1)"
[ -n "$chosen_wallpaper" ] || exit 1
set_wallpaper "$chosen_wallpaper"
}
random() {
wallpapers="$(echo "$(get_available_wallpapers)" | grep -vx "$(get_current_wallpaper)")"
wallpapers_count="$(echo "$wallpapers" | wc -l)"
[ "$wallpapers_count" -gt 0 ] || exit 1
set_wallpaper "$(echo "$wallpapers" | shuf -n 1)"
}
get_available_wallpapers() {
if ! [ -d "$WALLPAPERS_DIR" ]; then
echo "$WALLPAPERS_DIR is not a directory." >&2
exit 1
fi
find -L "$WALLPAPERS_DIR" -type f -iregex '.*\.\(png\|jpg\|jpeg\)'
}
set_wallpaper() {
feh --no-fehbg --bg-scale "$1"
ln -sf "$1" "$WALLPAPERS_DIR/current"
}
get_current_wallpaper() {
readlink -e "$WALLPAPERS_DIR/current"
}
help() {
cat >&2 << 'EOF'
Usage: weather [OPTIONS]
Options:
-l, --load Set most recent wallpaper $XDG_DATA_HOME/wallpapers/current.
-p, --pick Pick wallpaper from $XDG_DATA_HOME/wallpapers/.
-r, --random Set random wallpaper.
-h, --help Show this message and exit.
EOF
}
main "$@"