dotfiles/bin/random_wallpaper

62 lines
1.0 KiB
Plaintext
Raw Permalink Normal View History

2019-10-03 20:56:50 +00:00
#!/usr/bin/env bash
# random_wallpaper
#
# Requirement: feh (apt install feh)
directory="$HOME/wallpapers"
minutes=15
2021-06-25 23:15:49 +00:00
PROGRAM=`which feh`
2019-10-03 20:56:50 +00:00
# Some tests
2021-06-25 23:15:49 +00:00
if [[ "$XDG_SESSION_TYPE" -eq "wayland" ]]; then
PROGRAM=`which swaymsg`
if [ -z "${PROGRAM}" ]; then
echo "This script needs the swaymsg program."
exit 1
fi
wayland=1
elif [ -z "${PROGRAM}" ]; then
2019-10-03 20:56:50 +00:00
echo "This script needs the feh program. Install it."
2021-06-25 23:15:49 +00:00
exit 1
2019-10-03 20:56:50 +00:00
fi
if [ -d '$directory' ]; then
echo "No $directory found."
exit 1
fi
IFS="
"
array_files=($(ls -1 $directory))
nb_files=`ls $directory|wc -l`
if [ $nb_files == 0 ]; then
echo "$nb_files files in $directory"
exit 1
fi
# initialisation
seconds=$[ $minutes * 60 ]
while true; do
# Random number generator (not more than files number)
NUMBER=$[ ( $RANDOM % $nb_files ) ]
# Change background
file="${array_files["$NUMBER"]}"
2021-06-25 23:15:49 +00:00
if [[ -n wayland ]]; then
$PROGRAM output "*" bg "$directory/$file" fill
else
feh --bg-fill "$directory/$file"
fi
2019-10-03 20:56:50 +00:00
# Wait some times
sleep $seconds
done
exit 0