52 lines
1.4 KiB
Bash
Executable File
52 lines
1.4 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
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
|
|
interval=60
|
|
# 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
|
|
nitrogen) command="nitrogen --set-zoom-fill --save";;
|
|
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
|