-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbgchange
More file actions
executable file
·89 lines (73 loc) · 2.33 KB
/
bgchange
File metadata and controls
executable file
·89 lines (73 loc) · 2.33 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#! /bin/bash
## Options Parsing ##
function parseOptions(){
invalidOptionFlag=0 # set invalid option boolean
options=($@) # put the options into an array
while [ ${#options[@]} -gt 0 ]; do # while there are options to parse
case ${options} in # Examin the current option
(--*) # If it is a long option
case ${options} in # Parse the long option
(--flag-path)
options=(${options[@]#${options}})
if [ "${options:0:1}" == "-" ]; then
continue
else
flag_path="${options}"
options=(${options[@]#${options}})
continue
fi
;;
(*)
echo "invalid option ${options}"
invalidOptionFlag=1
;;
esac
;;
(-*) # If it is a short option
if [ ${#options} -lt 3 ]; then # If it is a single short option
case ${options} in
(-c)
cinnamon=1
;;
(*)
echo "invalid option ${options}"
invalidOptionFlag=1
;;
esac
else # Create single short options from combined short option
multiOption="${options}"
first="-${multiOption:1:1}"
remaining="-${multiOption:2}"
options=(${options[@]#${options}} $first $remaining)
continue
fi
;;
esac
options=(${options[@]#${options}}) # Remove the parsed option from options array
done
return $invalidOptionFlag
}
## Paths ##
flag_path='/home/krichardson/pictures/desktop_bg/flag'
bgheap_path='/home/krichardson/pictures/bgheap'
bg_path='/home/krichardson/pictures/desktop_bg/1265560742441'
cinnamon=0
## Parse options ##
parseOptions $@
## Variables ##
flag=`cat $flag_path`
bgheap=(`ls $bgheap_path`)
count=`echo ${bgheap[@]} | wc -w`
## Reset flag, if needed ##
if (( $flag == $count )); then echo '0' > $flag_path; flag=0; fi
## For random selection ##
(( selector = ($RANDOM % $count) ))
## Set new background ##
if [ $cinnamon -eq 0 ]; then
cp $bgheap_path/${bgheap[$selector]} $bg_path
else
feh --bg-scale $bgheap_path/${bgheap[$selector]}
fi
## Update flag file ##
let flag=$flag+1
echo $flag > $flag_path