diff --git a/rc/fzf-modules/sk-grep.kak b/rc/fzf-modules/sk-grep.kak new file mode 100644 index 0000000..39f9984 --- /dev/null +++ b/rc/fzf-modules/sk-grep.kak @@ -0,0 +1,52 @@ +# ╭─────────────╥────────────────────────╮ +# │ Author: ║ File: │ +# │ Andrey Orst ║ sk-grep.kak │ +# ╞═════════════╩════════════════════════╡ +# │ Module running interactive grep with │ +# │ ski for fzf.kak │ +# ╞══════════════════════════════════════╡ +# │ GitHub.com/andreyorst/fzf.kak │ +# ╰──────────────────────────────────────╯ + +declare-option -docstring "what command to use to provide list of grep search matches. +Grep output must follow the format of 'filename:line-number:text' + +Default value: + grep -RHn" \ +str fzf_sk_grep_command 'grep -RHn' + +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 +: open search result in new buffer. +: open search result in new window" + [ ! -z "${kak_client_env_TMUX}" ] && tmux_keybindings=" +: open search result in horizontal split +: open search result in vertical split" + + 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 %{fzf-sk-grep-handler} %{echo >/dev/null 2>&1} %{--expect ctrl-w $additional_flags} + set-option global fzf_implementation $impl" +}} + +define-command fzf-sk-grep-handler -params 1 %{ evaluate-commands %sh{ + printf "%s\n" "$1" | awk '{ + file = $0; sub(/:.*/, "", file); gsub("&", "&&", file); + line = $0; sub(/[^:]+:/, "", line); sub(/:.*/, "", line) + print "edit -existing %&" file "&; execute-keys %&" line "gxvc&"; + }' +}} + diff --git a/rc/fzf.kak b/rc/fzf.kak index 7d3c5ec..5453d23 100644 --- a/rc/fzf.kak +++ b/rc/fzf.kak @@ -176,7 +176,7 @@ fzf -params 2..4 %{ evaluate-commands %sh{ chmod 755 $fzfcmd if [ -n "$kak_client_env_TMUX" ]; then - [ -n "${tmux_height%%*%}" ] && measure="-p" || measure="-p" + [ -n "${tmux_height%%*%}" ] && measure="-l" || measure="-p" cmd="command tmux split-window $measure ${tmux_height%%%*} 'sh -c $fzfcmd'" elif [ -n "$kak_opt_termcmd" ]; then cmd="$kak_opt_termcmd 'sh -c $fzfcmd'" @@ -209,7 +209,7 @@ fzf -params 2..4 %{ evaluate-commands %sh{ fi ;; esac kakoune_command() { - printf "%s\n" "evaluate-commands -client $kak_client $wincmd $command %{$1}" + printf "%s\n" "evaluate-commands -client $kak_client $wincmd %{$command %{$1}}" [ -n "$extra_action" ] && printf "%s\n" "evaluate-commands -client $kak_client $extra_action" } while read item; do