-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbgch
executable file
·60 lines (53 loc) · 1.08 KB
/
bgch
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
#!/usr/bin/env bash
WP_DIR="/media/storage/pictures/wallpapers/"
N_IMG=$(ls "$WP_DIR" | wc -l)
INIT_IMG="$WP_DIR/$INIT_IMG"
DB_FILE="$HOME/data/wallpaper-db"
WP_FILE="$HOME/data/state-files/.wallpaper"
function ind_to_name {
index=$1
update_db
imgname=$(cat "$DB_FILE" | sed -n "${index}p")
echo "${WP_DIR}${imgname}"
}
function ind_to_set {
index=$1
img=$(ind_to_name $index)
echo "$index $img" >"$WP_FILE"
feh --bg-fill "$img"
}
function update_db {
ls "$WP_DIR" >"$DB_FILE"
}
function random_set {
r_n=$((RANDOM % $N_IMG + 1))
ind_to_set "$r_n"
}
function change_img {
r_i=$(cat "$WP_FILE" | cut -d " " -f 1)
delta=$1
r_o=$(((r_i + delta) % N_IMG))
ind_to_set $r_o
}
case $1 in
next)
change_img 1
;;
prev)
change_img -1
;;
init)
if [ ! -f "$WP_FILE" ]; then
random_set
else
img=$(cat "$WP_FILE" | cut -d " " -f 2)
feh --bg-fill "$img"
fi
;;
random)
random_set
;;
*)
change_img 1
;;
esac