Skip to content

Commit

Permalink
Select fzf notation for bind reload command dynamically
Browse files Browse the repository at this point in the history
Depending on what characters can be found in the command fed to
fzf, select the separator character for bind that does not
exist in the provided command string.

Falls back to `#` if all possible separators are present in the
command string.
  • Loading branch information
reegnz committed Oct 22, 2021
1 parent 97a6768 commit 79c0ebc
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion bin/jq-repl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ else
export FZF_JQ_REPL_COMMAND="jq-paths < \"$input\""
fi

fzf_notation_types="~!@#$%^&*;/|"
skip_notation="$(echo "$FZF_JQ_REPL_COMMAND" | sed -E "s,[^$fzf_notation_types],,g")"
fzf_notation="$(echo "$fzf_notation_types" | sed -E "s,[$skip_notation],,g" | head -c 1)"
if [ -z "$fzf_notation" ]; then
# fall back to default and hope for the best
fzf_notation="#"
fi

eval "$FZF_JQ_REPL_COMMAND" |
fzf \
--preview "jq --color-output ${JQ_REPL_ARGS:-} {q} \"$input\"" \
Expand All @@ -30,4 +38,4 @@ eval "$FZF_JQ_REPL_COMMAND" |
--query="." \
--bind "tab:replace-query,return:print-query" \
--bind "alt-up:preview-page-up,alt-down:preview-page-down" \
--bind "ctrl-r:reload#$FZF_JQ_REPL_COMMAND#+refresh-preview"
--bind "ctrl-r:reload${fzf_notation}${FZF_JQ_REPL_COMMAND}${fzf_notation}+refresh-preview"

0 comments on commit 79c0ebc

Please sign in to comment.