From: Siraaj Khandkar Date: Fri, 10 Jun 2022 17:07:00 +0000 (-0400) Subject: Improve wallpaper-setting pipeline robustness X-Git-Url: https://git.xandkar.net/?a=commitdiff_plain;h=fdc8785261d04be8df8158cf1eef192bf2d000e7;p=khome.git Improve wallpaper-setting pipeline robustness --- diff --git a/home/.xlaunch.d/background b/home/.xlaunch.d/background index ab4c301..a02d34c 100755 --- a/home/.xlaunch.d/background +++ b/home/.xlaunch.d/background @@ -3,8 +3,12 @@ set -e BG_COLOR='#b2b2a0' -BG_IMAGE=$(< "$FILE_WALLPAPER_CURR") #xsetroot -solid "$BG_COLOR" hsetroot -solid "$BG_COLOR" # Because xsetroot is incompatible with compton. -feh --bg-scale "$BG_IMAGE" + +if test -f "$FILE_WALLPAPER_CURR" +then + bg_image=$(< "$FILE_WALLPAPER_CURR") + feh --bg-scale "$bg_image" +fi diff --git a/home/bin/wallpaper_fav b/home/bin/wallpaper_fav index 702cd9f..1a73af7 100755 --- a/home/bin/wallpaper_fav +++ b/home/bin/wallpaper_fav @@ -2,5 +2,33 @@ set -e -awk 'NR == 2 {sub("^" $1 " +" $2 " +" $3 " +", ""); print}' ~/.fehbg | xargs sha256sum >> "$FILE_WALLPAPER_FAVS" +case "$1" in + '') + current_wallpaper_file=$( + awk ' + NR == 2 { + if (NF > 3) { + # XXX Assume feh wrote a N>4-field command line, like: + # feh --no-fehbg --bg-scale $file + sub("^" $1 " +" $2 " +" $3 " +", "") + } else if (NF < 4) { + # XXX Assume feh wrote a N<4-field command line, like: + # feh --bg-scale $file + sub("^" $1 " +" $2 " +", "") + } else { + printf "[error] Unexpected number of fields in ~/.fehbg command: %s\n" $0 > "/dev/stderr" + exit 1 + } + print + exit 0 + } + ' \ + ~/.fehbg \ + | xargs # Unquote the filename, which feh puts in single quotes. + );; + *) + current_wallpaper_file="$1" +esac + +sha256sum "$current_wallpaper_file" >> "$FILE_WALLPAPER_FAVS" sort -u "$FILE_WALLPAPER_FAVS" | sponge "$FILE_WALLPAPER_FAVS" diff --git a/home/bin/wallpaper_review b/home/bin/wallpaper_review index b466255..5c6966a 100755 --- a/home/bin/wallpaper_review +++ b/home/bin/wallpaper_review @@ -109,7 +109,7 @@ paths_preview() { (( i = (i + 1) % n ));; CMD_FAVORITE_ADD) printf 'Adding to favorites set: "%s"\n' "$path" >&2 - wallpaper_fav;; + wallpaper_fav "$path";; CMD_FAVORITE_REMOVE) printf 'Removing from favorites set: "%s"\n' "$path" >&2 digest=$(sha256sum "$path" | awk '{print $1}')