-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrwpm.sh
executable file
·172 lines (149 loc) · 5.33 KB
/
rwpm.sh
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#!/bin/bash
xkb-switch -s us &
rofi_command='rofi -m -1 -theme themes/wallpaper.rasi'
# Variable passed to rofi
options=(
"advanced download"
"download new"
"select random from saved"
"select last saved"
"select previous"
"save current wallpaper"
)
chosen="$(printf '%s\n' "${options[@]}" | $rofi_command -p "rwpm" -dmenu -selected-row 1)"
if [ -n "$chosen" ]; then
if [ "$(pgrep wallpaper | wc -l)" -gt 2 ]; then
notify-send "Please wait"
exit 1
fi
fi
storage_dir="$HOME/Pictures"
atleast="3840x2160"
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
-s | --storage-dir)
storage_dir="$2"
shift
shift
;;
-a | --atleast)
atleast="$2"
shift
shift
;;
*)
shift
;;
esac
done
wallpapers_dir="$storage_dir/wallpapers"
temp_wallpapers_dir="$wallpapers_dir/.temp_wallpapers"
# Wallpaper
wallpaper="$wallpapers_dir/wallpaper"
wallpaper_previous="$wallpapers_dir/wallpaper_previous"
clean_storage () {
find "$temp_wallpapers_dir" -mtime +1 ! -samefile "$(readlink -f "$wallpaper")" ! -samefile "$(readlink -f "$wallpaper_previous")" -exec rm {} +
}
clean_storage
case $chosen in
"download new")
img=$(swd -l "$temp_wallpapers_dir" -s views -a "$atleast")
ln -sf $(readlink -f "$wallpaper") "$wallpaper_previous"
ln -sf "$img" "$wallpaper" && feh --bg-fill "$wallpaper" >/dev/null
;;
"advanced download")
options=(
"absolute random"
"random from most viewed"
"random from latest"
"random from toplist"
"random from favorites"
"random and blurred"
)
chosen="$(printf '%s\n' "${options[@]}" | $rofi_command -p "select download option" -dmenu -selected-row 1)"
if [ -n "$chosen" ]; then
if [ "$(pgrep wallpaper | wc -l)" -gt 2 ]; then
notify-send "Please wait"
exit 1
fi
fi
case $chosen in
"absolute random")
img=$(swd -l "$temp_wallpapers_dir" -a "$atleast" -p 000)
ln -sf $(readlink -f "$wallpaper") "$wallpaper_previous"
ln -sf "$img" "$wallpaper" && feh --bg-fill "$wallpaper" >/dev/null
;;
"random from most viewed")
img=$(swd -l "$temp_wallpapers_dir" -s views -a "$atleast")
ln -sf $(readlink -f "$wallpaper") "$wallpaper_previous"
ln -sf "$img" "$wallpaper" && feh --bg-fill "$wallpaper" >/dev/null
;;
"random from latest")
img=$(swd -l "$temp_wallpapers_dir" -s latest -a "$atleast")
ln -sf $(readlink -f "$wallpaper") "$wallpaper_previous"
ln -sf "$img" "$wallpaper" && feh --bg-fill "$wallpaper" >/dev/null
;;
"random from toplist")
img=$(swd -l "$temp_wallpapers_dir" -s toplist -a "$atleast")
ln -sf $(readlink -f "$wallpaper") "$wallpaper_previous"
ln -sf "$img" "$wallpaper" && feh --bg-fill "$wallpaper" >/dev/null
;;
"random from favorites")
img=$(swd -l "$temp_wallpapers_dir" -s favorites -a "$atleast")
ln -sf $(readlink -f "$wallpaper") "$wallpaper_previous"
ln -sf "$img" "$wallpaper" && feh --bg-fill "$wallpaper" >/dev/null
;;
"random and blurred")
img=$(swd -l "$temp_wallpapers_dir")
convert -blur 0x80 "$img" "$img"
ln -sf $(readlink -f "$wallpaper") "$wallpaper_previous"
ln -sf "$img" "$wallpaper" && feh --bg-fill "$wallpaper" >/dev/null
;;
esac
;;
"select random from saved")
mapfile -t wallpapers < <(find "$wallpapers_dir" -maxdepth 1 -type f -regex ".*\.\(jpg\|gif\|png\|jpeg\)" ! -name "$(basename "$(readlink -f "$wallpaper")")")
ln -sf $(readlink -f "$wallpaper") "$wallpaper_previous"
ln -sf "${wallpapers[$(("$RANDOM" % ${#wallpapers[@]}))]}" "$wallpaper"
feh --bg-fill "$wallpaper" >/dev/null
;;
"select last saved")
# Получаем последнего сохранненого изображения
last_saved="$(ls "$wallpapers_dir" | tail -3 | head -n 1)"
ln -sf $(readlink -f "$wallpaper") "$wallpaper_previous"
ln -sf "$wallpapers_dir/$last_saved" "$wallpaper"
feh --bg-fill "$wallpaper" >/dev/null
;;
"select previous")
# Получаем путь предыдущего изображения
previous="$(readlink -f "$wallpaper_previous")"
ln -sf $(readlink -f "$wallpaper") "$wallpaper_previous"
ln -sf "$previous" "$wallpaper"
feh --bg-fill "$wallpaper" >/dev/null
;;
"save current wallpaper")
# Получаем путь текущего изображения
current_wallpaper="$(readlink -f "$wallpaper")"
PATTERN="$wallpapers_dir/*${current_wallpaper##*/}"
# Проверяем имеется ли такое изображение
if compgen -G "$PATTERN" >/dev/null; then
notify-send -u critical "Image already exists"
else
mkdir -p "$wallpapers_dir"
# Name of image
img="$(date +%y%m%d-%H%M%S)-${current_wallpaper##*/}"
# Copy the wallpaper image to archive folder
cp "$current_wallpaper" "$wallpapers_dir/$img"
notify-send "$img saved"
fi
;;
"")
;;
*)
# here bag: chosen is able to contain 2+ words
img=$(swd -l "$temp_wallpapers_dir" -q "$chosen" -a "$atleast")
ln -sf $(readlink -f "$wallpaper") "$wallpaper_previous"
ln -sf "$img" "$wallpaper" && feh --bg-fill "$wallpaper" >/dev/null
;;
esac