From 11f1d99cd21dc4f49ad206dc4cb4e69bc6243666 Mon Sep 17 00:00:00 2001 From: Andrey Orst Date: Wed, 27 Mar 2019 11:35:54 +0300 Subject: [PATCH] make `-items-smd' work like pipe; simplify sk-grep.kak --- rc/fzf.kak | 14 +++++++++++--- rc/modules/sk-grep.kak | 5 +---- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/rc/fzf.kak b/rc/fzf.kak index 144ba1d..8bb02e2 100644 --- a/rc/fzf.kak +++ b/rc/fzf.kak @@ -103,7 +103,8 @@ define-command -docstring \ 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. + -items-cmd : A command that is used as a pipe to provide list of values to fzf. + -fzf-impl : Owerride fzf implementation variable -fzf-args : Additional flags for fzf program -preview-cmd: a preview command -preview: should fzf window include preview @@ -113,7 +114,8 @@ fzf -shell-script-completion %{echo "-kak-cmd\n-items-cmd\n-fzf-args\n-post-acti while [ $# -gt 0 ]; do case $1 in -kak-cmd) shift; kakoune_cmd="$1" ;; - -items-cmd) shift; items_cmd="$1" ;; + -items-cmd) shift; items_cmd="$1 |" ;; + -fzf-impl) shift; fzf_impl="$1" ;; -fzf-args) shift; fzf_args="$1" ;; -preview-cmd) shift; preview_cmd="$1" ;; -preview) preview="true" ;; @@ -123,6 +125,10 @@ fzf -shell-script-completion %{echo "-kak-cmd\n-items-cmd\n-fzf-args\n-post-acti shift done + if [ -z "${fzf_impl}" ]; then + fzf_impl="${kak_opt_fzf_implementation}" + fi + if [ "${preview}" = "true" ]; then # bake position option to define them at runtime if [ -n "${kak_client_env_TMUX}" ]; then @@ -149,8 +155,10 @@ fzf -shell-script-completion %{echo "-kak-cmd\n-items-cmd\n-fzf-args\n-post-acti fzfcmd="${fzf_tmp}/fzfcmd" result="${fzf_tmp}/result" + shell_executable="$(command -v sh)" + # 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} ${filter} > ${result}; rm ${fzfcmd}" > ${fzfcmd} + printf "%s\n" "cd \"${PWD}\" && ${preview_position} ${items_cmd} SHELL=${shell_executable} ${fzf_impl} ${fzf_args} ${preview_cmd} ${filter} > ${result}; rm ${fzfcmd}" > ${fzfcmd} chmod 755 ${fzfcmd} if [ -n "${kak_client_env_TMUX}" ]; then diff --git a/rc/modules/sk-grep.kak b/rc/modules/sk-grep.kak index d95140b..f1a146f 100644 --- a/rc/modules/sk-grep.kak +++ b/rc/modules/sk-grep.kak @@ -38,10 +38,7 @@ define-command -hidden fzf-sk-grep %{ evaluate-commands %sh{ printf "%s\n" "info -title '${title}' '${message}${tmux_keybindings}'" [ ! -z "${kak_client_env_TMUX}" ] && additional_flags="--expect ctrl-v --expect ctrl-s" - impl=$kak_opt_fzf_implementation - printf "%s\n" "set-option global fzf_implementation %{sk -i -c '$kak_opt_fzf_sk_grep_command {}'} - fzf -kak-cmd %{fzf-sk-grep-handler} -items-cmd %{echo >/dev/null 2>&1} -fzf-args %{--expect ctrl-w $additional_flags} - set-option global fzf_implementation %{${impl}}" + printf "%s\n" "fzf -kak-cmd %{fzf-sk-grep-handler} -fzf-impl %{sk -i -c '$kak_opt_fzf_sk_grep_command {}'} -fzf-args %{--expect ctrl-w $additional_flags}" }} define-command -hidden fzf-sk-grep-handler -params 1 %{ evaluate-commands %sh{