-
Notifications
You must be signed in to change notification settings - Fork 5
/
betterfeh
executable file
·97 lines (85 loc) · 2.36 KB
/
betterfeh
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
#!/bin/bash
# Written By Woland
# Sets wallpapers and changes them automatically
#Dependency:
# feh
# change PIC_DIR to point to your wallpapers directory & run the script
# if -t is provided, it must precede other flags
# https://github.com/wolandark
# https://github.com/wolandark/BASH_Scripts_For_Everyone
#Default interval for changing the wallpapers
default_interval=120
#Wallpapers path
PIC_DIR="/home/woland/Pictures/HD/Landscape/"
PIC_LIST=("$PIC_DIR"*)
#Help msg
usage () {
echo "Usage: $0 [-h] [-t interval] [-e] [-r reverse]"
echo "Options:"
echo " -t interval Set wallpaper change interval in seconds (default: $default_interval). Must precede other flags if provided"
echo " -e Start from a random wallpaper"
echo " -r Set wallpaper in reverse order"
echo " -h Display this help message"
}
#Main Function
set_pic() {
local interval=${1:-$default_interval}
while true
do
if [ "$2" == "-r" ]; then
for (( i=${#PIC_LIST[@]}-1; i>=0; i-- ))
do
feh --bg-scale "${PIC_LIST[i]}"
sleep "${interval}"
done
elif [ "$2" == "-e" ]; then
random_pic=${PIC_LIST[$RANDOM % ${#PIC_LIST[@]}]}
for i in "${PIC_LIST[@]}"
do
feh --bg-scale "$i"
sleep "${interval}"
done
else
# Loop through the array normally if no flag is given
for i in "${PIC_LIST[@]}"
do
feh --bg-scale "$i"
sleep "${interval}"
done
fi
done
}
#getops
while getopts ":ht:re" opt; do
case ${opt} in
h ) usage
exit 0
;;
t )
interval=${OPTARG}
;;
r )
set_pic ${interval:-$default_interval} "-r"
exit 0
;;
e )
set_pic ${interval:-$default_interval} "-r"
exit 0
;;
\? )
echo "Invalid argument: -$OPTARG" 1>&2
exit 1
;;
: )
interval=${default_interval}
;;
esac
done
shift $((OPTIND -1))
interval=${interval:-$default_interval}
# Call the set_pic function
if [ -z "${1}" ]; then
set_pic ${interval}
else
set_pic ${1} ${interval}
fi