#!/bin/bash CONFIG_DIR="$HOME/.config/mbwallpaper" CONFIG_FILE="$CONFIG_DIR/mbwallpaper.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 < ${CONFIG_FILE} # Directory with wallpapers wallpaper_dir=/usr/share/backgrounds/ # Rotate time in seconds interval=10 # 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" ;; pcmanfm) command="pcmanfm -w" ;; *) echo "Unknown wallpaper setter. Please check your config file $CONFIG_FILE";exit 1;; esac #check if wallpaper dir was changed, if so delete wallpaper list if [ ! -f "$CONFIG_DIR/.lastdir" ]; then echo "$wallpaper_dir" > "$CONFIG_DIR/.lastdir" else lastdir=$(<$CONFIG_DIR/.lastdir) [[ "$wallpaper_dir" != "$lastdir" ]] && rm "$WALLPAPERS_LIST" && echo "$wallpaper_dir" > "$CONFIG_DIR/.lastdir" fi 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() { case $LANG in pl*) TITLE="Wybierz tapetę" TEXT="\nUżyj strzałek lub kółka myszy by nawigować.\nEnter by ustawić tapetę.\nEsc by wyjść." ;; *) TITLE="Select Wallpaper" TEXT="\nUse Arrows or mousewheel to navigate.\nEnter to set wallpaper.\nEsc to quit." ;; esac 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 emblem-photos "$TITLE" "$TEXT" 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 # 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 } 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