master
Daniel Napora 2021-05-28 03:32:29 +02:00
parent a5719c3512
commit a22bf909ca
1 changed files with 46 additions and 5 deletions

View File

@ -1,5 +1,4 @@
#!/bin/bash
CONFIG_DIR="$HOME/.config/chwp"
CONFIG_FILE="$CONFIG_DIR/chwp.conf"
WALLPAPERS_LIST="$CONFIG_DIR/wplist"
@ -13,7 +12,7 @@ cat <<EOF > ${CONFIG_FILE}
# Directory with wallpapers
wallpaper_dir=/usr/share/backgrounds/
# Rotate time in seconds
interval=60
interval=10
# Wallpaper setter program: nitrogen or feh
setter=nitrogen
EOF
@ -26,17 +25,44 @@ source <(grep = $CONFIG_FILE)
case "$setter" in
nitrogen) command="nitrogen --set-zoom-fill --save";;
feh) command="feh --bg-fill" ;;
pcmanfm) command="pcmanfm -w" ;;
*) echo "Unknown wallpaper setter. Please check your config file $CONFIG_FILE";exit 1;;
esac
while true
do
checkwplist() {
# 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
}
one() {
checkwplist
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}
exit 0
}
choose() {
SCREENSIZE=$(wmctrl -d |grep "*" | awk -F' ' '{print $4}')
W="${SCREENSIZE%x*}"
H="${SCREENSIZE#*x}"
FW=$((W/4))
FH=$((H/4))
X="40"
Y=$((H-FH-40))
notify-send.sh -u normal -i image "Select wallpaper" "\nUse <b>Arrows</b> or <b>mousewheel</b> to navigate.\n<b>Enter</b> to set wallpaper.\n<b>Esc</b> to quit."
feh -B "#4D4D4D" -N -x --scale-down -E ${FH} -y ${FW} -^ "Enter=select, Arrows=next,prev" -g ${FW}x${FH}+${X}+${Y} ${wallpaper_dir} -A "${command} %f"
}
slideshow() {
while true
do
checkwplist
# if wallpapers list have more than 0 lines
while [ $(wc -l <$WALLPAPERS_LIST) -gt 0 ]
do
@ -49,3 +75,18 @@ do
sleep ${interval}
done
done
}
usage() {
grep "^#:" $0 | while read DOC; do printf '%s\n' "${DOC###:}"; done
exit
}
case "$1" in
-o|one) one;;
-c|choose) choose;;
-h|--help) usage;;
*) slideshow;;
esac
exit 0