-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwp
More file actions
executable file
·65 lines (58 loc) · 1.91 KB
/
wp
File metadata and controls
executable file
·65 lines (58 loc) · 1.91 KB
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
#!/bin/sh
#
# summary: a simple posix wrapper script for setting wallpapers
# repository: https://github.com/hollowillow/scripts
#
# usage: wp [arg]
# arguments:
#
# random selects a random wallpaper
# select fuzzy search to select wallpaper
# help bring up this message
#
# dependencies: fzf, swaybg (wayland), fehbg (x11)
WALLPAPERS_DIR="${WALLPAPERS_DIR:-${XDG_DATA_HOME:-$HOME/.local/share}/wallpapers}"
mkdir -p "$WALLPAPERS_DIR" # create directory if it doesn't already exist
cd "$WALLPAPERS_DIR" || { printf '%s\n' "Error: $WALLPAPERS_DIR not found"; exit 2; }
printHelp() {
# creates a help message from comment block at the top of the file
sed "1,2d;s/^# //;s/^#$/ /;/^$/ q" "$0"; exit 0
}
setWallpaper() {
if [ "$(printenv XDG_SESSION_TYPE)" = wayland ]; then
pkill swaybg;
setsid swaybg --image "$1" & disown
elif [ "$(printenv XDG_SESSION_TYPE)" = x11 ]; then
fehbg --no-fehbg --bg-scale "$1" & exit 0
fi
}
randomWallpaper() {
WALLPAPER="$(find . -type f -not -path '*/\.git/*' | shuf -n 1)"
if [ -n "$WALLPAPER" ]; then
setWallpaper "$WALLPAPER";
printf '%s\n' "Set random wallpaper.";
else
printf '%s\n' "No file selected."; exit 1
fi
}
selectWallpaper() {
SELECTED="$(\
find . -type f -not -path '*/\.git/*' |
fzf --prompt "wallpaper: " \
--preview="previewer {}"
)"
if [ -n "$SELECTED" ]; then
setWallpaper "$SELECTED";
printf '%s\n' "Set selected wallpaper"; exit 0
else
sendFeedback "No file selected!"; exit 1
fi
}
main() {
case $1 in
help|-h|--help) printHelp;;
random) randomWallpaper;;
select) selectWallpaper;;
esac
}
main "$@"