From 0ea9b9b458f3d36033f73d7dc06102f274a55bb6 Mon Sep 17 00:00:00 2001 From: Andrey Orst Date: Sat, 2 Mar 2019 22:15:33 +0300 Subject: [PATCH] initial implementation of #39 --- rc/fzf-modules/sk-grep.kak | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 rc/fzf-modules/sk-grep.kak diff --git a/rc/fzf-modules/sk-grep.kak b/rc/fzf-modules/sk-grep.kak new file mode 100644 index 0000000..1dcdeb6 --- /dev/null +++ b/rc/fzf-modules/sk-grep.kak @@ -0,0 +1,38 @@ +# ╭─────────────╥────────────────────────╮ +# │ Author: ║ File: │ +# │ Andrey Orst ║ sk-grep.kak │ +# ╞═════════════╩════════════════════════╡ +# │ Module running interactive grep with │ +# │ ski for fzf.kak │ +# ╞══════════════════════════════════════╡ +# │ GitHub.com/andreyorst/fzf.kak │ +# ╰──────────────────────────────────────╯ + +declare-option str fzf_sk_grep_command 'grep -r' + +evaluate-commands %sh{ + if [ -n "$(command -v sk)" ]; then + printf "%s\n" "map global fzf -docstring %{Interactive grep with skim} 'g' ': sk-interactive-grep'" + fi +} + +define-command -hidden sk-interactive-grep %{ evaluate-commands %sh{ + if [ -z "$(command -v sk)" ]; then + printf "%s\n" "echo -markup %{{Information}skim required to run this command}" + exit + fi + title="skim interactive grep" + message="Interactively grep pattern from current directory" + printf "%s\n" "info -title '$title' '$message'" + impl=$kak_opt_fzf_implementation + printf "%s\n" "set-option global fzf_implementation sk + fzf %{fzf-sk-grep-handler} %{echo >/dev/null 2>&1} %{-i -c '$kak_opt_fzf_sk_grep_command {}'} + set-option global fzf_implementation $impl" +}} + +define-command fzf-sk-grep-handler -params 1 %{ evaluate-commands %sh{ + file="${1%%:*}" + pattern="${1##:*}" + printf "%s\n" "edit -existing %{$file}; execute-keys /\Q$pattern" +}} +