diff --git a/src/main.sh b/src/main.sh index c9de8f2..c48dd44 100755 --- a/src/main.sh +++ b/src/main.sh @@ -95,6 +95,15 @@ MODE_INSERT="show" . "sh/fzf.sh" # Command-line options that may only be used internally. +# --lines +# --playback +# --playlist +# --action-playlistcursor +# --action-filter +# --action-gotoartist +# --action-draw +# --mbsearch +# --preview-artist case "${1:-}" in "--lines") # Print lines that are fed into fzf. @@ -172,7 +181,42 @@ case "${1:-}" in esac exit 0 ;; -"--filter") +"--playlist") + # Run playback commands + # + # @argument $2: playback command (see `src/sh/playback.sh`) + # + # This is a wrapper to execute mpv commands. + case "$2" in + "$PLAYLIST_CMD_REMOVE") mpv_rm_index $((FZF_POS - 1)) ;; + "$PLAYLIST_CMD_UP") mpv_playlist_move $((FZF_POS - 1)) $((FZF_POS - 2)) ;; + "$PLAYLIST_CMD_DOWN") mpv_playlist_move $((FZF_POS - 0)) $((FZF_POS - 1)) ;; + "$PLAYLIST_CMD_CLEAR") mpv_playlist_clear ;; + "$PLAYLIST_CMD_CLEAR_ABOVE") + for i in $(seq "$FZF_POS"); do + mpv_rm_index 0 + done + ;; + "$PLAYLIST_CMD_CLEAR_BELOW") + cnt=$(mpv_playlist_count) + rem=$((cnt - FZF_POS + 1)) + for i in $(seq "$rem"); do + mpv_rm_index $((FZF_POS - 1)) + done + ;; + esac + exit 0 + ;; +"--action-playlistcursor") + # Print fzf command to replace cursor in playlist + # + # This prints the command read by a `transform` fzf binding, with which the + # cursor is placed on the currently played track in the playlist view. + pos=$(mpv_playlist_position) + printf "pos(%s)" $((pos + 1)) + exit 0 + ;; +"--action-filter") # fzf instructions to invoke filters # # @argument #2: mode @@ -189,7 +233,7 @@ case "${1:-}" in [ "$mode" = "$MODE_NORMAL" ] && printf "+hide-input" exit 0 ;; -"--jumpto-artist") +"--action-gotoartist") # fzf instructions to go to artist # # @argument $2: mode @@ -223,10 +267,10 @@ case "${1:-}" in 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)+print(%s)+print(%s)+accept" "$VIEW_SELECT_ARTIST" "$j" "$view" "$mbid_cur" + [ "${aid:-}" ] && $0 --action-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") +"--action-draw") # Generate fzf command to draw screen. # # @argument $2: mode (default `normal`) @@ -320,7 +364,7 @@ case "${1:-}" in [ "$mode" = "$MODE_NORMAL" ] && printf "+hide-input" exit 0 ;; -"--fzf-change") +"--mbsearch") # Trigger search on MusicBrainz # # @argument $2: view @@ -331,6 +375,21 @@ case "${1:-}" in fzf_handle_change "$2" exit 0 ;; +"--preview-artist") + # Generate content for artist preview + # + # @argument $2: MusicBrainz Artist ID + # + # This prints the text to be displayed in the preview window for the + # specified artist. + __preview_artist "$2" + exit 0 + ;; +esac + +# Non-interactive user commands intended to the user. These commands do not +# require temporary files, fzf, nor the mpv instance. +case "${1:-}" in "--decorate") # Decorate directory with tagged audio files # @@ -362,51 +421,6 @@ case "${1:-}" in info "Done" exit 0 ;; -"--preview-artist") - # Generate content for artist preview - # - # @argument $2: MusicBrainz Artist ID - # - # This prints the text to be displayed in the preview window for the - # specified artist. - __preview_artist "$2" - exit 0 - ;; -"--playlistcmd") - # Run playback commands - # - # @argument $2: playback command (see `src/sh/playback.sh`) - # - # This is a wrapper to execute mpv commands. - case "$2" in - "$PLAYLIST_CMD_REMOVE") mpv_rm_index $((FZF_POS - 1)) ;; - "$PLAYLIST_CMD_UP") mpv_playlist_move $((FZF_POS - 1)) $((FZF_POS - 2)) ;; - "$PLAYLIST_CMD_DOWN") mpv_playlist_move $((FZF_POS - 0)) $((FZF_POS - 1)) ;; - "$PLAYLIST_CMD_CLEAR") mpv_playlist_clear ;; - "$PLAYLIST_CMD_CLEAR_ABOVE") - for i in $(seq "$FZF_POS"); do - mpv_rm_index 0 - done - ;; - "$PLAYLIST_CMD_CLEAR_BELOW") - cnt=$(mpv_playlist_count) - rem=$((cnt - FZF_POS + 1)) - for i in $(seq "$rem"); do - mpv_rm_index $((FZF_POS - 1)) - done - ;; - esac - exit 0 - ;; -"--playlist-place-cursor") - # Print fzf command to replace cursor in playlist - # - # This prints the command read by a `transform` fzf binding, with which the - # cursor is placed on the currently played track in the playlist view. - pos=$(mpv_playlist_position) - printf "pos(%s)" $((pos + 1)) - exit 0 - ;; "--help") # Print help string cat <