mabox-tools/bin/mbwallpaper

105 lines
2.8 KiB
Plaintext
Raw Normal View History

2021-05-14 19:35:19 +02:00
#!/bin/bash
2021-05-30 01:51:41 +02:00
CONFIG_DIR="$HOME/.config/mbwallpaper"
CONFIG_FILE="$CONFIG_DIR/mbwallpaper.conf"
2021-05-14 19:35:19 +02:00
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-28 03:32:29 +02:00
interval=10
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" ;;
2021-05-28 03:32:29 +02:00
pcmanfm) command="pcmanfm -w" ;;
2021-05-14 19:35:19 +02:00
*) echo "Unknown wallpaper setter. Please check your config file $CONFIG_FILE";exit 1;;
esac
2021-05-28 03:32:29 +02:00
checkwplist() {
2021-05-14 19:35:19 +02:00
# 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
2021-05-28 03:32:29 +02:00
}
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() {
2021-05-30 01:51:41 +02:00
case $LANG in
pl*)
TITLE="Wybierz tapetę"
TEXT="\nUżyj <b>strzałek</b> lub <b>kółka myszy</b> by nawigować.\n<b>Enter</b> by ustawić tapetę.\n<b>Esc</b> by wyjść."
;;
*)
TITLE="Select Wallpaper"
TEXT="\nUse <b>Arrows</b> or <b>mousewheel</b> to navigate.\n<b>Enter</b> to set wallpaper.\n<b>Esc</b> to quit."
;;
esac
2021-05-28 03:32:29 +02:00
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))
2021-05-30 01:51:41 +02:00
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'"
2021-05-28 03:32:29 +02:00
}
slideshow() {
while true
do
checkwplist
2021-05-14 19:35:19 +02:00
# 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
2021-05-28 03:32:29 +02:00
}
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