3 ### XXX Chose not to 'set -e' because arithmetic evaluation can cause a non-zero exit.
4 ### XXX Chose not to 'set -u' because unset params ($1, $2, ...) cause failures.
5 ### Solutions to the above are ugly.
19 if [[ "$buf" =~ ^
[0-9]+$
]]; then
20 if [[ "$buf" -gt 0 && "$buf" -le "$n" ]]; then
25 printf 'Error: out of range: %s\n' "$buf" >&2
29 printf 'Error: not an integer: %s\n' "$buf" >&2
39 q | Q
) _command
='CMD_QUIT';;
40 h | H
) _command
='CMD_MOVE_BACK';;
41 l | L
) _command
='CMD_MOVE_FORWARD';;
42 f | F
) _command
='CMD_FAVORITE_ADD';;
43 r | R
) _command
='CMD_FAVORITE_REMOVE';;
44 s | S
) _command
='CMD_SET_CURRENT';;
45 z | Z
) _command
='CMD_FZF';;
46 :) read_command_goto
;;
48 printf 'Error: unknown command: %s\n' "$char" >&2
49 _command
='CMD_UKNOWN';;
58 if file "$path" |
grep 'image data' > /dev
/null
61 # \r jumps to the beginning of the line:
62 printf '\rFound %d images.' "$n" >&2
63 paths
["$(( n - 1 ))"]="$path"
69 paths_set_from_dir_find
() {
70 paths_set
< <(find "$1" -type f
)
73 paths_set_from_favs
() {
74 paths_set
< <(sort -k 2 "$FILE_WALLPAPER_FAVS" |
awk '{sub("^" $1 " +", ""); print}')
81 printf '%d of %d %s\n' "$(( i + 1 ))" "$n" "$path"
82 feh
--bg-scale "$path"
87 local path
="${paths[$i]}"
89 set_wallpaper
"$i" "$path"
93 if [[ "${paths[$i]}" != "$path" ]]
96 set_wallpaper
"$i" "$path"
102 feh
--bg-scale "$(< "$FILE_WALLPAPER_CURR")"
107 (( i
= i
== 0 ?
(n
- 1) : i
- 1));;
109 (( i
= (i
+ 1) % n
));;
111 printf 'Adding to favorites set: "%s"\n' "$path" >&2
112 wallpaper_fav
"$path";;
114 printf 'Removing from favorites set: "%s"\n' "$path" >&2
115 digest
=$
(sha256sum
"$path" |
awk '{print $1}')
116 grep -v "$digest" "$FILE_WALLPAPER_FAVS" \
118 | sponge
"$FILE_WALLPAPER_FAVS"
121 printf 'Setting as current: "%s"\n' "$path" >&2
122 echo "$path" > "$FILE_WALLPAPER_CURR";;
125 for j
in "${!paths[@]}"; do
126 printf '%d %s\n' "$((j + 1))" "${paths[j]}"
129 |
awk '{print $1 - 1}'
143 ----+----------------------------------------------
148 r | remove from favorites
150 z | fuzzy search for next file path
152 ----+----------------------------------------------
160 $(basename "$0") [cmd]
163 ----+-------+------------------------------------------------
165 d | <dir> | from given dir
166 a | | all from $DIR_WALLPAPERS <- DEFAULT if no cmd.
167 h | | usage help. i.e. this message.
168 ----+-------+------------------------------------------------
175 f | fav
) paths_set_from_favs
;;
176 d | dir
) paths_set_from_dir_find
"$2";;
177 a | all
) paths_set_from_dir_find
"$DIR_WALLPAPERS";;
178 h |
-h |
help |
-help |
--help)
182 paths_set_from_dir_find
"$DIR_WALLPAPERS";;
184 printf 'Error: unknown source "%s"\n' "$1" >&2
This page took 0.128445 seconds and 4 git commands to generate.