fixes and history (1 level)

from VIEW_PLAYLIST and VIEW_SELECT_ARTIST we can now go "back"
This commit is contained in:
2025-09-07 14:08:54 +02:00
parent dfcae7cf89
commit 70da0ed282
3 changed files with 36 additions and 129 deletions

View File

@@ -218,14 +218,14 @@ case "${1:-}" in
"$VIEW_SEARCH_ARTIST" | "$VIEW_LIST_ARTISTS") aid="$mbid" ;;
esac
if [ "$view" = "$VIEW_PLAYLIST" ]; then
printf "print(%s)+print(%s)+accept" "$VIEW_SELECT_ARTIST" "$j"
printf "print(%s)+print(%s)+print(%s)+print(%s)+accept" "$VIEW_SELECT_ARTIST" "$j" "$view" "$mbid_cur"
exit 0
fi
if [ "${j:-}" ]; then
cnt=$(echo "$j" | $JQ 'length')
[ "$cnt" -eq 1 ] && aid="$(echo "$j" | $JQ -r '.[0].artist.id')"
fi
[ "${aid:-}" ] && $0 --draw "$mode" "$VIEW_ARTIST" "$aid" || printf "print(%s)+print(%s)+accept" "$VIEW_SELECT_ARTIST" "$j"
[ "${aid:-}" ] && $0 --draw "$mode" "$VIEW_ARTIST" "$aid" || printf "print(%s)+print(%s)+print(%s)+print(%s)+accept" "$VIEW_SELECT_ARTIST" "$j" "$view" "$mbid_cur"
exit 0
;;
"--draw")
@@ -322,18 +322,6 @@ case "${1:-}" in
[ "$mode" = "$MODE_NORMAL" ] && printf "+hide-input"
exit 0
;;
"--fzf-reload")
fzf_handle_reload
exit 0
;;
"--fzf-load")
fzf_handle_load
exit 0
;;
"--fzf-info")
fzf_info
exit 0
;;
"--fzf-change-reload")
fzf_reload_after_change
exit 0
@@ -521,27 +509,34 @@ while true; do
case "$VIEW" in
"$VIEW_SELECT_ARTIST")
sel=$(
echo "$ARGS" |
list_artists_from_json |
$FZF \
--bind="$KEYS_HALFPAGE_DOWN,$KEYS_HALFPAGE_UP,\
$KEYS_BROWSE,\
$KEYS_OPEN,\
$KEYS_FILTER_LOCAL:transform:$0 --fzf-key {2} {3} {4}" \
-0 -1 \
--border="bold" \
--border-label="Select artist" \
--delimiter="\t" \
--prompt="$SEARCH_PROMPT" \
--margin="5%,20%" \
--bind="$KEYS_FILTER_LOCAL:change-query('$QUERY_LOCAL' )" \
--accept-nth="{3}" \
--with-nth="{1}" || true
echo "$ARGS" | list_artists_from_json | $FZF \
--bind="$KEYS_DOWN:down" \
--bind="$KEYS_UP:up" \
--bind="$KEYS_HALFPAGE_DOWN:half-page-down" \
--bind="$KEYS_HALFPAGE_UP:half-page-up" \
--bind="enter,$KEYS_IN:print($VIEW_ARTIST)+accept" \
--bind="$KEYS_OUT,$KEYS_QUIT:print($LASTVIEW)+print($LASTARG)+print($VIEW_SELECT_ARTIST)+print($ARGS)+accept" \
--bind="$KEYS_LIST_ARTISTS:print($VIEW_LIST_ARTISTS)+accept" \
--bind="$KEYS_LIST_ALBUMS:print($VIEW_LIST_ALBUMS)+accept" \
--bind="$KEYS_SEARCH_ARTIST:print($VIEW_SEARCH_ARTIST)+accept" \
--bind="$KEYS_SEARCH_ALBUM:print($VIEW_SEARCH_ALBUM)+accept" \
--bind="$KEYS_BROWSE:execute-silent:open \"https://musicbrainz.org/artist/{r3}\"" \
--bind="$KEYS_SHOW_PLAYLIST:print($VIEW_PLAYLIST)+print()+print($VIEW_SELECT_ARTIST)+print($ARGS)+accept" \
-0 -1 \
--border="bold" \
--border-label="Select artist" \
--delimiter="\t" \
--prompt="$SEARCH_PROMPT" \
--margin="5%,20%" \
--bind="$KEYS_FILTER_LOCAL:change-query('$QUERY_LOCAL' )" \
--accept-nth="{3}" \
--with-nth="{1}" || true
)
[ "$sel" ] || continue
MODE="$MODE_NORMAL"
VIEW="$VIEW_ARTIST"
MBID="$sel"
debug "$sel"
VIEW="$(echo "$sel" | head -1)"
MBID="$(echo "$sel" | head -2 | tail -1)"
LASTVIEW="$(echo "$sel" | head -3 | tail -1)"
LASTARG="$(echo "$sel" | head -4 | tail -1)"
;;
"$VIEW_PLAYLIST")
sel=$(
@@ -558,6 +553,7 @@ $KEYS_FILTER_LOCAL:transform:$0 --fzf-key {2} {3} {4}" \
--bind="$KEYS_HALFPAGE_UP:half-page-up" \
--bind="$KEYS_N_BOT:last" \
--bind="$KEYS_N_TOP:first" \
--bind="$KEYS_OUT,$KEYS_N_OUT,$KEYS_QUIT,$KEYS_N_QUIT:print($LASTVIEW)+print($LASTARG)+print($VIEW_PLAYLIST)+print()+accept" \
--bind="$KEYS_SELECT_ARTIST:transform:$0 --jumpto-artist $MODE_NORMAL $VIEW_PLAYLIST {2} {3}" \
--bind="$KEYS_LIST_ARTISTS:print($VIEW_LIST_ARTISTS)+accept" \
--bind="$KEYS_LIST_ALBUMS:print($VIEW_LIST_ALBUMS)+accept" \
@@ -574,7 +570,6 @@ $KEYS_FILTER_LOCAL:transform:$0 --fzf-key {2} {3} {4}" \
--bind="$KEYS_PLAYLIST_CLEAR_ABOVE:execute-silent($0 --playlistcmd $PLAYLIST_CMD_CLEAR_ABOVE)+$FZF_RELOAD_PLAYLIST" \
--bind="$KEYS_PLAYLIST_CLEAR_BELOW:execute-silent($0 --playlistcmd $PLAYLIST_CMD_CLEAR_BELOW)+$FZF_RELOAD_PLAYLIST" \
--bind="$KEYS_PLAYLIST_GOTO_RELEASE:print($VIEW_RELEASE)+accept" \
--bind="$KEYS_PLAYLIST_QUIT:print($VIEW_LIST_ARTISTS)+accept" \
--delimiter="\t" \
--with-nth="{1}" \
--accept-nth="{2}" || true
@@ -582,6 +577,8 @@ $KEYS_FILTER_LOCAL:transform:$0 --fzf-key {2} {3} {4}" \
VIEW="$(echo "$sel" | head -1)"
ARGS="$(echo "$sel" | head -2 | tail -1)"
MBID=$ARGS
LASTVIEW="$(echo "$sel" | head -3 | tail -1)"
LASTARG="$(echo "$sel" | head -4 | tail -1)"
;;
"$VIEW_QUIT")
break
@@ -651,7 +648,7 @@ open \"https://musicbrainz.org/\$t/{r3}\"" \
--bind="$KEYS_OPEN:execute-silent:
[ {4} ] || exit 0
open \"\$(dirname {4})\"" \
--bind="$KEYS_SHOW_PLAYLIST:print($VIEW_PLAYLIST)+accept" \
--bind="$KEYS_SHOW_PLAYLIST:transform:echo \"print($VIEW_PLAYLIST)+print()+print($FZF_CURRENT_VIEW)+print({2})+accept\"" \
--bind="$KEYS_QUIT:print($VIEW_QUIT)+accept" \
--bind="$KEYS_N_QUIT:transform:$IN_NORMAL_MODE && ($IN_LIST_ARTISTS_VIEW && echo \"print($VIEW_QUIT)+accept\" || $0 --draw $MODE_NORMAL $VIEW_LIST_ARTISTS) || $PUT_FZF_KEY_LOGIC" \
--bind="$KEYS_PLAYBACK:transform:$0 --playback $FZF_CURRENT_VIEW {2} {3} {4}" \
@@ -664,10 +661,8 @@ open \"\$(dirname {4})\"" \
)
VIEW="$(echo "$sel" | head -1)"
ARGS="$(echo "$sel" | head -2 | tail -1)"
LASTVIEW="$(echo "$sel" | head -3 | tail -1)"
LASTARG="$(echo "$sel" | head -4 | tail -1)"
;;
esac
done
#[ \"$MODE\" = \"$MODE_NORMAL\" ] && echo \"+hide-input\" || echo \"+show-input\"
# --bind="load:transform:$0 --fzf-load" \
# --bind="change:execute-silent($0 --fzf-change &)+reload:$0 --fzf-change-reload" \
# --bind="$KEYS_ALL:transform:$0 --fzf-key {2} {3} {4}" \

View File

@@ -79,93 +79,6 @@ __set_prompt() {
printf "+change-header(%s %s)" "$PT" "${PROMPT:-"$SEARCH_PROMPT"}"
}
# Reload data for FZF
fzf_handle_reload() {
view=$(state_get_view)
mode=$(state_get_mode)
args=$(state_get_args)
case "$view" in
"$VIEW_ARTIST")
list_releasegroups "$args"
;;
"$VIEW_RELEASEGROUP")
list_releases "$args"
;;
"$VIEW_RELEASE")
list_recordings "$args"
;;
"$VIEW_LIST_ARTISTS")
list_local_artists
;;
"$VIEW_LIST_ALBUMS")
list_local_releasegroups
;;
esac
}
# Handle for after loading data into FZF
fzf_handle_load() {
view=$(state_get_view)
mode=$(state_get_mode)
args=$(state_get_args)
case "$view" in
"$VIEW_ARTIST")
QUERY="!'$QUERY_HAS_SECONDARY' "
;;
"$VIEW_RELEASEGROUP")
[ "$QUERY_RV" ] && QUERY="'$QUERY_RV' " || QUERY=""
;;
"$VIEW_SEARCH_ARTIST")
ENABLE_CHANGE=1
DISABLE_SEARCH=1
SHOW_PREVIEW=1
;;
"$VIEW_SEARCH_ALBUM")
ENABLE_CHANGE=1
DISABLE_SEARCH=1
;;
"$VIEW_LIST_ARTISTS")
SHOW_PREVIEW=1
;;
"$VIEW_LIST_ALBUMS") ;;
esac
[ "${DISABLE_SEARCH:-}" ] && printf "+disable-search+change-query(%s)+disable-search" "${QUERY:-"$FZF_QUERY"}" || printf "+enable-search+change-query(%s)+enable-search" "${QUERY:-}"
[ "${SHOW_PREVIEW:-}" ] && printf "+show-preview" || printf "+hide-preview"
[ "${ENABLE_CHANGE:-}" ] && printf "+rebind(change)" || printf "+unbind(change)"
__set_prompt "$view" "$mode"
}
# Print info string for FZF
fzf_info() {
view=$(state_get_view)
mode=$(state_get_mode)
args=$(state_get_args)
case "$view" in
"$VIEW_SEARCH_ARTIST")
echo "Search music artist on MusicBrainz"
;;
"$VIEW_SEARCH_ALBUM")
echo "Search album on MusicBrainz"
;;
"$VIEW_LIST_ARTISTS")
echo "Search artists"
;;
"$VIEW_LIST_ALBUMS")
echo "Search albums"
;;
"$VIEW_SELECT_ARTIST")
debug "Select artist (WE SHOULDNT SEE THIS; THIS IS A BUG!)"
;;
*)
if [ "$FZF_KEY" ]; then
printf "[last key: %s] %s/%s" "$FZF_KEY" "$FZF_MATCH_COUNT" "$FZF_TOTAL_COUNT"
else
printf "%s/%s" "$FZF_MATCH_COUNT" "$FZF_TOTAL_COUNT"
fi
;;
esac
}
# Reload hook that is used after change in query
fzf_reload_after_change() {
# Wait for async. process to terminate

View File

@@ -123,7 +123,7 @@ KEYS_FILTER="$KEYS_FILTER_LOCAL,$KEYS_FILTER_1,$KEYS_FILTER_2,$KEYS_FILTER_3,$KE
KEYS_BROWSE="${KEYS_BROWSE:-"alt-b"}"
KEYS_OPEN="${KEYS_OPEN:-"alt-o"}"
KEYS_SHOW_PLAYLIST="${KEYS_SHOW_PLAYLIST:-"ctrl-p"}"
KEYS_QUIT="${KEYS_QUIT:-"ctrl-c"}"
KEYS_QUIT="${KEYS_QUIT:-"ctrl-c,esc"}"
KEYS_N_QUIT="${KEYS_N_QUIT:-"q"}"
# Playback:
@@ -157,7 +157,6 @@ KEYS_PLAYLIST_CLEAR_BELOW="${KEYS_PLAYLIST_CLEAR_BELOW:-"D"}"
KEYS_PLAYLIST_GOTO_RELEASE="${KEYS_PLAYLIST_GOTO_RELEASE:-"ctrl-g"}"
KEYS_PLAYLIST_STORE="${KEYS_PLAYLIST_STORE:-"ctrl-s"}"
KEYS_PLAYLIST_LOAD="${KEYS_PLAYLIST_LOAD:-"ctrl-o"}"
KEYS_PLAYLIST_QUIT="${KEYS_PLAYLIST_QUIT:-"q,ctrl-c,esc"}"
## Not yet characterized
##########################