From f42cbcb86f8cd81622514f33a997d38767ae5ecb Mon Sep 17 00:00:00 2001 From: Andrey Orst Date: Wed, 27 Mar 2019 11:14:23 +0300 Subject: [PATCH] new filter flag, which acts like final pipe after fzf command --- rc/fzf.kak | 17 +++++++++-------- rc/modules/fzf-search.kak | 2 +- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/rc/fzf.kak b/rc/fzf.kak index b084391..144ba1d 100644 --- a/rc/fzf.kak +++ b/rc/fzf.kak @@ -105,19 +105,20 @@ Switches: -kak-cmd : A Kakoune cmd that is applied to fzf resulting value. -items-cmd : A command that is used to provide list of values to fzf. -fzf-args : Additional flags for fzf program - -post-action : Extra commands that are preformed after `-kak-cmd' command. -preview-cmd: a preview command - -preview: should fzf window include preview" \ + -preview: should fzf window include preview + -filter : A pipe which will be applied to result provided by fzf + -post-action : Extra commands that are preformed after `-kak-cmd' command." \ fzf -shell-script-completion %{echo "-kak-cmd\n-items-cmd\n-fzf-args\n-post-action\n"} -params .. %{ evaluate-commands %sh{ while [ $# -gt 0 ]; do case $1 in -kak-cmd) shift; kakoune_cmd="$1" ;; - -items-cmd) shift; items_cmd="$1" ;; - -fzf-args) shift; fzf_args="$1" ;; - -post-action) shift; post_action="$1" ;; + -items-cmd) shift; items_cmd="$1" ;; + -fzf-args) shift; fzf_args="$1" ;; -preview-cmd) shift; preview_cmd="$1" ;; - -preview) preview="true" ;; - *) ;; + -preview) preview="true" ;; + -filter) shift; filter="| $1" ;; + -post-action) shift; post_action="$1" ;; esac shift done @@ -149,7 +150,7 @@ fzf -shell-script-completion %{echo "-kak-cmd\n-items-cmd\n-fzf-args\n-post-acti result="${fzf_tmp}/result" # compose entire fzf command with all args into single file which will be executed later - printf "%s\n" "cd \"${PWD}\" && ${preview_position} ${items_cmd} | SHELL=$(command -v sh) ${kak_opt_fzf_implementation} ${fzf_args} ${preview_cmd} > ${result}; rm ${fzfcmd}" > ${fzfcmd} + printf "%s\n" "cd \"${PWD}\" && ${preview_position} ${items_cmd} | SHELL=$(command -v sh) ${kak_opt_fzf_implementation} ${fzf_args} ${preview_cmd} ${filter} > ${result}; rm ${fzfcmd}" > ${fzfcmd} chmod 755 ${fzfcmd} if [ -n "${kak_client_env_TMUX}" ]; then diff --git a/rc/modules/fzf-search.kak b/rc/modules/fzf-search.kak index 0329318..e4af11a 100644 --- a/rc/modules/fzf-search.kak +++ b/rc/modules/fzf-search.kak @@ -17,6 +17,6 @@ define-command -hidden fzf-buffer-search %{ evaluate-commands %sh{ printf "%s\n" "info -title '$title' '$message'" buffer_content="$(mktemp ${TMPDIR:-/tmp}/fzf-buff-${kak_buffile##*/}.XXXXXX)" printf "%s\n" "execute-keys -draft %{%cat>$buffer_content;}" - printf "%s\n" "fzf -kak-cmd %{execute-keys} -items-cmd %{(nl -b a -n ln $buffer_content; rm $buffer_content)} -fzf-args %{--reverse | cut -f 1} -post-action %{execute-keys gx}" + printf "%s\n" "fzf -kak-cmd %{execute-keys} -items-cmd %{(nl -b a -n ln $buffer_content; rm $buffer_content)} -fzf-args %{--reverse} -filter %{cut -f 1} -post-action %{execute-keys gx}" }}