mabox-tools/bin/chwp

52 lines
1.4 KiB
Plaintext
Raw Normal View History

2021-05-14 19:35:19 +02:00
#!/bin/bash
2021-05-23 13:18:24 +02:00
2021-05-14 19:35:19 +02:00
CONFIG_DIR="$HOME/.config/chwp"
CONFIG_FILE="$CONFIG_DIR/chwp.conf"
WALLPAPERS_LIST="$CONFIG_DIR/wplist"
# Make config directory if not exist
mkdir -p $CONFIG_DIR
# If config file not exist create one with defaults
if [ ! -f $CONFIG_FILE ]; then
cat <<EOF > ${CONFIG_FILE}
# Directory with wallpapers
wallpaper_dir=/usr/share/backgrounds/
# Rotate time in seconds
2021-05-23 13:18:24 +02:00
interval=60
2021-05-14 19:35:19 +02:00
# Wallpaper setter program: nitrogen or feh
setter=nitrogen
EOF
fi
# read config variables from file
source <(grep = $CONFIG_FILE)
# decide which setter and command use to set wallpaper
case "$setter" in
2021-05-23 13:18:24 +02:00
nitrogen) command="nitrogen --set-zoom-fill --save";;
2021-05-14 19:35:19 +02:00
feh) command="feh --bg-fill" ;;
*) echo "Unknown wallpaper setter. Please check your config file $CONFIG_FILE";exit 1;;
esac
while true
do
# If list does not exist or is empty
if [[ ! -f $WALLPAPERS_LIST || $(wc -l <$WALLPAPERS_LIST) -lt 1 ]]; then
# Prepare list with wallpapers (only PNG and JPG)
ls -1 "$wallpaper_dir"/*{.jpg,.png} > "$WALLPAPERS_LIST"
fi
# if wallpapers list have more than 0 lines
while [ $(wc -l <$WALLPAPERS_LIST) -gt 0 ]
do
# get random line
line=$(shuf -n 1 $WALLPAPERS_LIST)
#delete it from list
grep -v "$line" "$WALLPAPERS_LIST" > "$CONFIG_DIR/tmpfile"; mv "$CONFIG_DIR/tmpfile" "$WALLPAPERS_LIST"
#run command to set wallpaper
${command} ${line}
sleep ${interval}
done
done