From a22bf909ca27436202fc2f62f4e81ed6a479c957 Mon Sep 17 00:00:00 2001 From: Daniel Napora Date: Fri, 28 May 2021 03:32:29 +0200 Subject: [PATCH] chwp --- bin/chwp | 51 ++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 46 insertions(+), 5 deletions(-) diff --git a/bin/chwp b/bin/chwp index f9bcd56..3517c4e 100755 --- a/bin/chwp +++ b/bin/chwp @@ -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 < ${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 Arrows or mousewheel to navigate.\nEnter to set wallpaper.\nEsc 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