67 lines
1.3 KiB
Fish
Executable File
67 lines
1.3 KiB
Fish
Executable File
#!/usr/bin/env fish
|
|
|
|
# This script randomly switches the background (through fehbg) every 5 to 30 minutes.
|
|
# It selects a random image from the ~/Pictures/Wallpapers folder (including subdirectories)
|
|
# Any hidden files in this folder are excluded.
|
|
|
|
# in-place awk script
|
|
set awkcommand '
|
|
BEGIN {
|
|
FS=", "
|
|
width=1920
|
|
height=1080
|
|
}
|
|
|
|
|
|
NR == 1 {
|
|
x = $1
|
|
y = $2
|
|
|
|
if (x < 0) {
|
|
x = width + x
|
|
}
|
|
|
|
if (y < 0) {
|
|
y = height + y
|
|
}
|
|
|
|
print x "," y
|
|
}
|
|
'
|
|
|
|
# kill old instances
|
|
for i in (ps -C (basename (status filename)) | awk 'FNR>1 {print $1}')
|
|
if test $i -ne $fish_pid
|
|
kill $i
|
|
end
|
|
end
|
|
|
|
|
|
# set bg
|
|
swaybg -i $(find ~/Pictures/wallpapers -type f -regextype posix-extended -iregex "/(.*/)*[^\.]*\.(png|jpe?g|webp|gif)" | sort -R | head -n1)
|
|
while true
|
|
set rand (math "(floor $(random 300 1800) / 60) * 60")
|
|
|
|
# countdown
|
|
while test $rand -gt 0
|
|
set minutes (math "floor $rand / 60 ")
|
|
|
|
printf '\r\033[K%.2d:00' $minutes
|
|
|
|
sleep 60
|
|
set rand (math $rand - 60 )
|
|
end
|
|
|
|
# update wallpaper
|
|
swaybg -i $(find ~/Pictures/wallpapers -type f -regextype posix-extended -iregex "/(.*/)*[^\.]*\.(png|jpe?g|webp|gif)" | sort -R | head -n1)
|
|
set newpid $last_pid
|
|
sleep 0.2
|
|
for pid in (pgrep -x swaybg)
|
|
if test $pid -ne $last_pid
|
|
kill $pid
|
|
end
|
|
end
|
|
end
|
|
|
|
|