X-Git-Url: https://git.xandkar.net/?a=blobdiff_plain;f=home%2Fbin%2Fwallpaper_review;h=8b15bcb677d0822ed3fd1237115bd8ce631bdef7;hb=1cbcd78facb72fef9eb038ffe9237d427875791d;hp=34d98d79e24472a9890802bd5dbcc43b029293f9;hpb=6ec50bf3e0c31dddcbb7e35f81e9b50c9811154b;p=khome.git diff --git a/home/bin/wallpaper_review b/home/bin/wallpaper_review index 34d98d7..8b15bcb 100755 --- a/home/bin/wallpaper_review +++ b/home/bin/wallpaper_review @@ -7,18 +7,46 @@ declare -a paths declare -i n=0 +declare _command +declare -i _goto=0 + +read_command_goto() { + local buf + + printf ':' >&2 + read -r buf + printf '\n' >&2 + if [[ "$buf" =~ ^[0-9]+$ ]]; then + if [[ "$buf" -gt 0 && "$buf" -le "$n" ]]; then + (( buf-- )) + _goto="$buf" + _command='CMD_GOTO' + else + printf 'Error: out of range: %s\n' "$buf" >&2 + _command='CMD_UKNOWN' + fi + else + printf 'Error: not an integer: %s\n' "$buf" >&2 + _command='CMD_UKNOWN' + fi +} + read_command() { local char read -rsn 1 char case "$char" in - q | Q) echo 'CMD_QUIT';; - h | H) echo 'CMD_MOVE_BACK';; - l | L) echo 'CMD_MOVE_FORWARD';; - f | F) echo 'CMD_FAVORITE_ADD';; - r | R) echo 'CMD_FAVORITE_REMOVE';; - s | S) echo 'CMD_SET_CURRENT';; - *) echo 'CMD_UKNOWN';; + q | Q) _command='CMD_QUIT';; + h | H) _command='CMD_MOVE_BACK';; + l | L) _command='CMD_MOVE_FORWARD';; + f | F) _command='CMD_FAVORITE_ADD';; + r | R) _command='CMD_FAVORITE_REMOVE';; + s | S) _command='CMD_SET_CURRENT';; + z | Z) _command='CMD_FZF';; + :) read_command_goto;; + *) + printf 'Error: unknown command: %s\n' "$char" >&2 + _command='CMD_UKNOWN';; esac } @@ -68,16 +96,20 @@ paths_preview() { set_wallpaper "$i" "$path" fi - case "$(read_command)" in + read_command + case "$_command" in CMD_QUIT) + feh --bg-scale "$(< "$FILE_WALLPAPER_CURR")" exit 0;; + CMD_GOTO) + i="$_goto";; CMD_MOVE_BACK) (( i = i == 0 ? (n - 1) : i - 1));; CMD_MOVE_FORWARD) (( 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}') @@ -88,24 +120,71 @@ paths_preview() { CMD_SET_CURRENT) printf 'Setting as current: "%s"\n' "$path" >&2 echo "$path" > "$FILE_WALLPAPER_CURR";; + CMD_FZF) + i=$( + for j in "${!paths[@]}"; do + printf '%d %s\n' "$((j + 1))" "${paths[j]}" + done \ + | fzf -e \ + | awk '{print $1 - 1}' + );; CMD_UKNOWN) continue;; esac done } +help_print() { + cat <&2 + +Navigation help: + +key | action +----+---------------------------------------------- + q | quit + h | move back + l | move forward + f | add to favorites + r | remove from favorites + s | set current + z | fuzzy search for next file path + :N | goto Nth image +----+---------------------------------------------- + +EOF +} + +usage() { + cat <&2 + +$(basename "$0") [cmd] + +cmd | args | meaning +----+-------+------------------------------------------------ + f | | favorites + d | | from given dir + a | | all from $DIR_WALLPAPERS <- DEFAULT if no cmd. + h | | usage help. i.e. this message. +----+-------+------------------------------------------------ + +EOF +} + main() { case "$1" in f | fav) paths_set_from_favs;; d | dir) paths_set_from_dir_find "$2";; a | all) paths_set_from_dir_find "$DIR_WALLPAPERS";; + h | -h | help | -help | --help) + usage; + exit 1;; '') paths_set_from_dir_find "$DIR_WALLPAPERS";; *) printf 'Error: unknown source "%s"\n' "$1" >&2 exit 1;; esac - + help_print paths_preview }