From 9f8d2cc1895beeb0184b76d71865ebbe8cad70dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=84min=20Baumeler?= Date: Thu, 4 Sep 2025 22:52:25 +0200 Subject: [PATCH] ctrl-a key works again --- src/main.sh | 69 ++++++++++++++++++++++++++------------------------ src/sh/keys.sh | 13 ++++++++-- 2 files changed, 47 insertions(+), 35 deletions(-) diff --git a/src/main.sh b/src/main.sh index 8e87f7f..c029744 100755 --- a/src/main.sh +++ b/src/main.sh @@ -11,6 +11,7 @@ VIEW_LIST_ARTISTS="list-artists" VIEW_LIST_ALBUMS="list-albums" VIEW_SELECT_ARTIST="select-artist" VIEW_PLAYLIST="playlist" +VIEW_QUIT="quit" MODE_NORMAL="hidden" MODE_INSERT="show" @@ -85,6 +86,26 @@ case "${1:-}" in esac exit 0 ;; +"--jumpto-artist") + mode=$2 + view=$3 + mbid_cur="${4:-}" + mbid="${5:-}" + case "$view" in + "$VIEW_ARTIST" | "$VIEW_SEARCH_ALBUM" | "$VIEW_LIST_ALBUMS") j="$(mb_releasegroup "$mbid" | $JQ -r --compact-output '."artist-credit"')" ;; + "$VIEW_RELEASEGROUP") j="$(mb_release "$mbid" | $JQ -r --compact-output '."artist-credit"')" ;; + "$VIEW_RELEASE") j="$(mb_release "$mbid_cur" | $JQ -r --compact-output ".media | map(.tracks) | flatten[] | select(.id == \"$mbid\") | .\"artist-credit\"")" ;; + "$VIEW_SEARCH_ARTIST" | "$VIEW_LIST_ARTISTS") aid="$mbid" ;; + esac + if [ "${j:-}" ]; then + cnt=$(echo "$j" | $JQ 'length') + [ "$cnt" -eq 1 ] && aid="$(echo "$j" | $JQ -r '.[0].artist.id')" + debug "cnt=$cnt; artistid=${artistid:-}" + fi + [ "${aid:-}" ] && debug "$0 --draw \"$mode\" \"$VIEW_ARTIST\" \"$aid\"" || debug "$(printf "print(%s)+print(%s)+accept" "$VIEW_SELECT_ARTIST" "$j")" + [ "${aid:-}" ] && $0 --draw "$mode" "$VIEW_ARTIST" "$aid" || printf "print(%s)+print(%s)+accept" "$VIEW_SELECT_ARTIST" "$j" + exit 0 + ;; "--draw") debug "call to $*" # Generate fzf command to draw screen. @@ -338,12 +359,10 @@ mpv_start IN_NORMAL_MODE="[ \"\$FZF_INPUT_STATE\" = \"hidden\" ]" PUT_FZF_KEY_LOGIC="case \"\$FZF_KEY\" in \"space\") echo \"put( )\";; \"backspace\"|\"bspace\"|\"bs\") echo \"backward-delete-char\";; \"delete\"|\"del\") echo \"delete-char\";; *) echo \"put(\$FZF_KEY)\";; esac" while true; do - mode=$(state_get_mode) - args=$(state_get_args) case "$VIEW" in "$VIEW_SELECT_ARTIST") sel=$( - echo "$args" | + echo "$ARGS" | list_artists_from_json | $FZF \ --bind="$KEYS_HALFPAGE_DOWN,$KEYS_HALFPAGE_UP,\ @@ -360,7 +379,10 @@ $KEYS_FILTER_LOCAL:transform:$0 --fzf-key {2} {3} {4}" \ --accept-nth="{3}" \ --with-nth="{1}" || true ) - [ "$sel" ] && state_update "$VIEW_ARTIST" "$mode" "$sel" || state_revert + [ "$sel" ] || continue + MODE="$MODE_NORMAL" + VIEW="$VIEW_ARTIST" + MBID="$sel" ;; "$VIEW_PLAYLIST") list_playlist | @@ -376,6 +398,10 @@ $KEYS_FILTER_LOCAL:transform:$0 --fzf-key {2} {3} {4}" \ --delimiter="\t" \ --with-nth="{1}" >/dev/null ;; + "$VIEW_QUIT") + debug "Quitting..." + break + ;; *) # Main instance # @@ -388,33 +414,7 @@ $KEYS_FILTER_LOCAL:transform:$0 --fzf-key {2} {3} {4}" \ # naturally printable or modifications of the input string. See # `$PUT_FZF_KEY_LOGIC` for details. # - # Here is a list of all keys grouped by type. - # - # Mode selection: - # - $KEYS_I_NORMAL: Switch to normal mode (insert mode) - # - $KEYS_N_INSERT: Switch to insert mode (normal mode) - # - # Vertical navigation: - # - $KEYS_DOWN: Move cursor to the next line - # - $KEYS_UP: Move cursor to the previous line - # - $KEYS_HALFPAGE_UP: Move cursor half a page up - # - $KEYS_HALFPAGE_DOWN: Move cursor half a page up - # - $KEYS_N_DOWN: Move cursor to the next line (normal mode) - # - $KEYS_N_UP: Move cursor to the previous line (normal mode) - # - $KEYS_N_BOT: Move cursor to the last line (normal mode) - # - $KEYS_N_TOP: Move cursor to the first line (normal mode) - # - # Horizontal navigation: - # - $KEYS_IN: Enter into selected item, down the hierarchy - # - $KEYS_OUT: Leave current item, up the hierarchy - # - # Filtering: - # - # Playback: - # - # Extras: - # - $KEYS_BROWSE: Open MusicBrainz webpage of the selected item - # - $KEYS_OPEN: Open file manager in the directory of the selected item + # Here is a list of all keys grouped by type (see `src/sh/keys.sh`). #--bind="start:change-border-label($VIEW)+change-list-label($MBID)+$MODE-input+transform:$0 --display" \ sel=$( printf "" | $FZF \ @@ -437,6 +437,7 @@ $KEYS_FILTER_LOCAL:transform:$0 --fzf-key {2} {3} {4}" \ --bind="$KEYS_OUT:transform:[ {2} ] && $0 --draw \$FZF_INPUT_STATE \$FZF_BORDER_LABEL {2} \"-1\"" \ --bind="$KEYS_N_IN:transform:$IN_NORMAL_MODE && ([ {3} ] && $0 --draw \$FZF_INPUT_STATE \$FZF_BORDER_LABEL {3} \"+1\") || $PUT_FZF_KEY_LOGIC" \ --bind="$KEYS_N_OUT:transform:$IN_NORMAL_MODE && ([ {2} ] && $0 --draw \$FZF_INPUT_STATE \$FZF_BORDER_LABEL {2} \"-1\") || $PUT_FZF_KEY_LOGIC" \ + --bind="$KEYS_JUMPTO_ARTIST:transform:$0 --jumpto-artist \$FZF_INPUT_STATE \$FZF_BORDER_LABEL {2} {3}" \ --bind="$KEYS_BROWSE:execute-silent: [ {3} ] || exit 0 case \"\$FZF_BORDER_LABEL\" in @@ -460,11 +461,13 @@ open \"\$(dirname {4})\"" \ --bind="$KEYS_PLAY:" \ --bind="$KEYS_QUEUE:" \ --bind="$KEYS_SHOW_PLAYLIST:" \ - --expect="ctrl-c" \ + --bind="$KEYS_QUIT:print($VIEW_QUIT)+accept" \ --delimiter="\t" \ --with-nth="{1}" || true ) - [ "$(echo "$sel" | head -1)" = "ctrl-c" ] && break + VIEW="$(echo "$sel" | head -1)" + ARGS="$(echo "$sel" | head -2 | tail -1)" + debug "FZF terminated: view=$VIEW, ARGS=$ARGS" ;; esac done diff --git a/src/sh/keys.sh b/src/sh/keys.sh index a21d301..c69c27f 100644 --- a/src/sh/keys.sh +++ b/src/sh/keys.sh @@ -1,4 +1,4 @@ -# See comment in `src/main.sh` on key bindings. +# List of keys, organized in groups # # Mode selection: # - $KEYS_I_NORMAL: Switch to normal mode (insert mode) @@ -19,14 +19,17 @@ # - $KEYS_OUT: Leave current item, up the hierarchy # - $KEYS_N_IN: Enter into selected item, down the hierarchy (normal mode) # - $KEYS_N_OUT: Leave current item, up the hierarchy (normal mode) +# - $KEYS_JUMPTO_ARTIST: Go to artist of selected entry (in case of multiple +# artists, provide a choice) # # Filtering: # # Playback: # -# Extras: +# Specials: # - $KEYS_BROWSE: Open MusicBrainz webpage of the selected item # - $KEYS_OPEN: Open file manager in the directory of the selected item +# - $KEYS_QUIT: Quit application # Mode selection: KEYS_I_NORMAL="${KEYS_I_NORMAL:-"esc"}" @@ -47,6 +50,12 @@ KEYS_IN="${KEYS_IN:-"ctrl-l"}" KEYS_OUT="${KEYS_OUT:-"ctrl-h"}" KEYS_N_IN="${KEYS_N_IN:-"l"}" KEYS_N_OUT="${KEYS_N_OUT:-"h"}" +KEYS_JUMPTO_ARTIST="${KEYS_JUMPTO_ARTIST:-"ctrl-a"}" + +# ... + +# Specials: +KEYS_QUIT="${KEYS_QUIT:-"ctrl-c"}" ## Not yet characterized KEYS_N_QUIT="${KEYS_N_QUIT:-"q"}"