-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwpm
executable file
·241 lines (211 loc) · 5.65 KB
/
wpm
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
#!/usr/bin/env bash
#
# ############################################################################
# Project: scripts (none)
# File...: wpm
# Created: Tuesday, 2019/12/20 - 09:55:58
# Author.: @fbnmtz, ([email protected])
# ~·~·~·~·~·~·~·~·~·~·~·~·~~·~·~·~·~·~·~·~·~·~·~·~·~~·~·~·~·~·~~·~·~·~·~·~·~·~
# Last Modified: Thursday, 2023/07/13 - 00:07:59
# Modified By..: @fbnmtz, ([email protected])
# ~·~·~·~·~·~·~·~·~·~·~·~·~~·~·~·~·~·~·~·~·~·~·~·~·~~·~·~·~·~·~~·~·~·~·~·~·~·~
# Version: 1.2.3.119
# ~·~·~·~·~·~·~·~·~·~·~·~·~~·~·~·~·~·~·~·~·~·~·~·~·~~·~·~·~·~·~~·~·~·~·~·~·~·~
# Description:
# >
# ############################################################################
# HISTORY:
#
configure(){
# script name
APP=$(basename "$0")
# wallpapers directory
WALLPAPERS_DIR=~/wallpapers
# scritp home for temp files
MYHOME=/tmp/$APP
mkdir -p $MYHOME
# store all wallpapers
FILES=$MYHOME/files
# updateLIST
# status files to avoid multiple runs
statusfile=$MYHOME/status.log
GIFFILE=$MYHOME/gifs
mkdir -p $GIFFILE
}
status.create(){
# create temp status file
if [ ! -f $statusfile ]; then
touch $statusfile
fi
sts=$(cat $statusfile | grep -m 1 'status=' | cut -d '=' -f 2)
if [ "$sts" != "running" ]; then
# echo "status=running" > $statusfile
echo "seconds=$TIME" >> $statusfile
echo "root=$WALLPAPERS_DIR" >> $statusfile
fi
}
setWallpaper(){
file=$1
filetype="$(basename $file | cut -d '.' -f 2)"
# [ -z "$lastpid" ] && lastpid='x'
if [ "$filetype" == "gif" ]; then
# pkill setGifWallpaper 2> /dev/null
# setGifWallpaper -w 0.010 -f $file &
# pkill wallpaper-video 2> /dev/null
# for i in $(ps -aux | grep mpv | grep "\-\-mute \-\-wid=0" | aw 2); do
# kill -9 $i
# done
for i in $(ps -aux | grep mpv | grep "\-\-mute \-\-wid=0" | aw 2); do kill -9 $i; done
# kill -9 $lastpid
wallpaper-video $file &
# lastpid=$!
else
# pkill setGifWallpaper 2> /dev/null
# pkill wallpaper-video 2> /dev/null
# kill -9 $lastpid
feh --bg-fill "$file"
# for i in $(ps -aux | grep mpv | grep "\-\-mute \-\-wid=0" | aw 2); do kill -9 $i; done
fi
}
setTime(){
requireARGS "$@"
ptime=${1}
# get current time in status file
ctime=$(cat $statusfile | grep -m 1 'seconds=' )
if [ "$ctime" != "" ]; then
if [ "$(echo $ctime | cut -d '=' -f2 )" != "$ptime" ]; then
sed -i -e "/seconds=/d" $statusfile
TIME=$ptime
echo "seconds=$TIME" >> $statusfile
return 1
fi
sed -i -e "/seconds=/d" $statusfile
fi
TIME=$ptime
echo "seconds=$TIME" >> $statusfile
}
usage(){
usage_info="
usage: $APP -t [SECONDS] -r [PATH] -d
-t, --time [value] time to daemon wait in each wallpaper
-r, --root [path] folder with images to use as wallpaper
-d, --daemon starts a daemon to change wallpaper after \$time
-s, --status prints daemon info
-w, --wallpaper prints current wallpaper
-q, --quit stop daemon"
echo -e "$usage_info"
}
# catch ctrl-c interrupt
function interruptManager {
echo "-- $APP interrupted $@"
# if [ "$1" == "2" ];then
rm $MYHOME/*
exit 2
# fi
}
wploop(){
sts=$(cat $statusfile | grep -m 1 'status=' | cut -d '=' -f 2)
if [ "$sts" != "running" ]; then
echo "status=running" >> $statusfile
while true; do
# for file in ${FILES[@]}; do
while IFS= read file; do
# wait time with each wallpaper
wtime=$(cat $statusfile | grep -m 1 'seconds=' | cut -d '=' -f 2)
# set image file as backgroud (convert to create a FADE effect)
# convert $lastfile -fill black -colorize 50% transition.bg
# feh --bg-scale transition.bg
# convert $file -fill black -colorize 50% transition.bg
# feh --bg-scale transition.bg
# feh --bg-fill "$file"
setWallpaper $file
# if set BG is executed with no erros
if [[ ${PIPESTATUS[0]} -eq 0 ]]; then
# get current wallpaper name to
# set new gif update
current=$(cat $statusfile | grep -m 1 'wallpaper=')
if [ "$current" == "" ]; then
echo "wallpaper=$file" >> $statusfile
else
# sed -i -e "s/[^=]*$/$file/g;t;d" $statusfile
sed -i -e "/wallpaper=/d" $statusfile
echo "wallpaper=$file" >> $statusfile
fi
#feh --randomize --bg-fill -r $1
sleep $wtime
fi
# save current file to make a FADE EFFECT
lastfile=$file
done < $FILES
done
else
puts r "$APP already running"
fi
}
setROOT(){
requireARGS "$@"
WALLPAPERS_DIR=$1
sed -i -e "/root=/d" $statusfile
echo "root=$WALLPAPERS_DIR" >> $statusfile
updateLIST
}
updateLIST(){
find "$WALLPAPERS_DIR" -type f | sort -R > $FILES
}
requireARGS(){
if [ "$1" == "" ]; then
usage
exit 1
fi
}
# main app
configure
requireARGS "$@"
# if [[ $# -eq 0 ]]; then
# usage
# exit 1
# fi
trap "interruptManager" 2 KILL QUIT SIGTERM
# INT TERM KILL QUIT EXIT SIGTERM
# 2 3 6 9 14 15
while [ "$1" != "" ]; do
case "$1" in
-n | --next) puts next ;;
-p | --prev) puts prev ;;
-d | --daemon)
# status.create
updateLIST
wploop &
;;
-t | --time)
shift
setTime $1
;;
-r | --root)
shift
setROOT $1
puts "updated root folder to: $1"
;;
-s | --status)
if [ -f $statusfile ]; then
cat $statusfile
else
puts "$APP daemon not running. use -d option to start a daemon."
fi
exit 1
;;
-w | --wallpaper)
if [ -f $statusfile ]; then
wpp="$(cat $statusfile | grep -m 1 'wallpaper=' | cut -d '=' -f2)"
echo $wpp
# echo $wpp | xclip-cmd
else
puts "$APP daemon not running. use -d option to start a daemon."
fi
;;
-q | --quit)
pkill -x wpm && rm -rf $MYHOME && pkill setGifWallpaper
;;
esac
shift
done