Improve wallpaper-setting pipeline robustness
[khome.git] / home / bin / wallpaper_fav
1 #! /bin/sh
2
3 set -e
4
5 case "$1" in
6 '')
7 current_wallpaper_file=$(
8 awk '
9 NR == 2 {
10 if (NF > 3) {
11 # XXX Assume feh wrote a N>4-field command line, like:
12 # feh --no-fehbg --bg-scale $file
13 sub("^" $1 " +" $2 " +" $3 " +", "")
14 } else if (NF < 4) {
15 # XXX Assume feh wrote a N<4-field command line, like:
16 # feh --bg-scale $file
17 sub("^" $1 " +" $2 " +", "")
18 } else {
19 printf "[error] Unexpected number of fields in ~/.fehbg command: %s\n" $0 > "/dev/stderr"
20 exit 1
21 }
22 print
23 exit 0
24 }
25 ' \
26 ~/.fehbg \
27 | xargs # Unquote the filename, which feh puts in single quotes.
28 );;
29 *)
30 current_wallpaper_file="$1"
31 esac
32
33 sha256sum "$current_wallpaper_file" >> "$FILE_WALLPAPER_FAVS"
34 sort -u "$FILE_WALLPAPER_FAVS" | sponge "$FILE_WALLPAPER_FAVS"
This page took 0.063569 seconds and 4 git commands to generate.