populate grep buffer
This commit is contained in:
parent
a64699d214
commit
77f3eddac6
2 changed files with 35 additions and 10 deletions
25
rc/fzf.kak
25
rc/fzf.kak
|
@ -103,6 +103,7 @@ define-command -docstring \
|
||||||
|
|
||||||
Switches:
|
Switches:
|
||||||
-kak-cmd <command>: A Kakoune cmd that is applied to fzf resulting value
|
-kak-cmd <command>: A Kakoune cmd that is applied to fzf resulting value
|
||||||
|
-multiple-cmd <command>: A Kakoune cmd that is applied all multiple selected files but the first one
|
||||||
-items-cmd <items command>: A command that is used as a pipe to provide list of values to fzf
|
-items-cmd <items command>: A command that is used as a pipe to provide list of values to fzf
|
||||||
-fzf-impl <implementation>: Owerride fzf implementation variable
|
-fzf-impl <implementation>: Owerride fzf implementation variable
|
||||||
-fzf-args <args>: Additional flags for fzf program
|
-fzf-args <args>: Additional flags for fzf program
|
||||||
|
@ -112,6 +113,7 @@ Switches:
|
||||||
-post-action <commands>: Extra commands that are preformed after `-kak-cmd' command" \
|
-post-action <commands>: Extra commands that are preformed after `-kak-cmd' command" \
|
||||||
-shell-script-completion %{
|
-shell-script-completion %{
|
||||||
printf "%s\n" "-kak-cmd
|
printf "%s\n" "-kak-cmd
|
||||||
|
-multiple-cmd
|
||||||
-items-cmd
|
-items-cmd
|
||||||
-fzf-impl
|
-fzf-impl
|
||||||
-fzf-args
|
-fzf-args
|
||||||
|
@ -125,17 +127,20 @@ fzf -params .. %{ evaluate-commands %sh{
|
||||||
|
|
||||||
while [ $# -gt 0 ]; do
|
while [ $# -gt 0 ]; do
|
||||||
case $1 in
|
case $1 in
|
||||||
-kak-cmd) shift; kakoune_cmd="$1" ;;
|
-kak-cmd) shift; kakoune_cmd="$1" ;;
|
||||||
-items-cmd) shift; items_cmd="$1 |" ;;
|
-multiple-cmd) shift; multiple_cmd="$1" ;;
|
||||||
-fzf-impl) shift; fzf_impl="$1" ;;
|
-items-cmd) shift; items_cmd="$1 |" ;;
|
||||||
-fzf-args) shift; fzf_args="$1" ;;
|
-fzf-impl) shift; fzf_impl="$1" ;;
|
||||||
-preview-cmd) shift; preview_cmd="$1" ;;
|
-fzf-args) shift; fzf_args="$1" ;;
|
||||||
-preview) preview="true" ;;
|
-preview-cmd) shift; preview_cmd="$1" ;;
|
||||||
-filter) shift; filter="| $1" ;;
|
-preview) preview="true" ;;
|
||||||
-post-action) shift; post_action="$1" ;;
|
-filter) shift; filter="| $1" ;;
|
||||||
|
-post-action) shift; post_action="$1" ;;
|
||||||
esac; shift
|
esac; shift
|
||||||
done
|
done
|
||||||
|
|
||||||
|
[ -z "$multiple_cmd" ] && multiple_cmd="$kakoune_cmd"
|
||||||
|
|
||||||
if [ "${preview}" = "true" ]; then
|
if [ "${preview}" = "true" ]; then
|
||||||
# bake position option to define them at runtime
|
# bake position option to define them at runtime
|
||||||
if [ -n "${kak_client_env_TMUX}" ]; then
|
if [ -n "${kak_client_env_TMUX}" ]; then
|
||||||
|
@ -196,8 +201,12 @@ fzf -params .. %{ evaluate-commands %sh{
|
||||||
esac
|
esac
|
||||||
if [ -n "${item}" ]; then
|
if [ -n "${item}" ]; then
|
||||||
printf "%s\n" "evaluate-commands -client ${kak_client} ${wincmd} %{${kakoune_cmd} %{${item}}}"
|
printf "%s\n" "evaluate-commands -client ${kak_client} ${wincmd} %{${kakoune_cmd} %{${item}}}"
|
||||||
|
break
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
while read line; do
|
||||||
|
printf "%s\n" "evaluate-commands -client ${kak_client} ${wincmd} %{${multiple_cmd} %{${line}}}"
|
||||||
|
done
|
||||||
if [ -n "${post_action}" ]; then
|
if [ -n "${post_action}" ]; then
|
||||||
printf "%s\n" "evaluate-commands -client ${kak_client} %{${post_action}}"
|
printf "%s\n" "evaluate-commands -client ${kak_client} %{${post_action}}"
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -15,6 +15,8 @@ Default value:
|
||||||
grep -RHn" \
|
grep -RHn" \
|
||||||
str fzf_sk_grep_command 'grep -RHn'
|
str fzf_sk_grep_command 'grep -RHn'
|
||||||
|
|
||||||
|
declare-option -hidden str fzf_sk_first_file ''
|
||||||
|
|
||||||
try %{ declare-user-mode fzf }
|
try %{ declare-user-mode fzf }
|
||||||
|
|
||||||
evaluate-commands %sh{
|
evaluate-commands %sh{
|
||||||
|
@ -38,14 +40,28 @@ define-command -hidden fzf-sk-grep %{ evaluate-commands %sh{
|
||||||
|
|
||||||
printf "%s\n" "info -title '${title}' '${message}${tmux_keybindings}'"
|
printf "%s\n" "info -title '${title}' '${message}${tmux_keybindings}'"
|
||||||
[ ! -z "${kak_client_env_TMUX}" ] && additional_flags="--expect ctrl-v --expect ctrl-s"
|
[ ! -z "${kak_client_env_TMUX}" ] && additional_flags="--expect ctrl-v --expect ctrl-s"
|
||||||
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}"
|
printf "%s\n" "fzf -kak-cmd %{fzf-sk-grep-handler} -fzf-impl %{sk -m -i -c '$kak_opt_fzf_sk_grep_command {}'} -fzf-args %{--expect ctrl-w $additional_flags} -multiple-cmd %{fzf-sk-populate-grep} -post-action %{buffer %opt{fzf_sk_first_file}}"
|
||||||
}}
|
}}
|
||||||
|
|
||||||
define-command -hidden fzf-sk-grep-handler -params 1 %{ evaluate-commands %sh{
|
define-command -hidden fzf-sk-grep-handler -params 1 %{ evaluate-commands %sh{
|
||||||
printf "%s\n" "$1" | awk '{
|
printf "%s\n" "$1" | awk '{
|
||||||
file = $0; sub(/:.*/, "", file); gsub("&", "&&", file);
|
file = $0; sub(/:.*/, "", file); gsub("&", "&&", file);
|
||||||
line = $0; sub(/[^:]+:/, "", line); sub(/:.*/, "", line)
|
line = $0; sub(/[^:]+:/, "", line); sub(/:.*/, "", line)
|
||||||
print "edit -existing %&" file "&; execute-keys %&" line "gxvc&";
|
print "edit -existing %&" file "&; execute-keys %&" line "gxvc&"
|
||||||
|
print "set-option global fzf_sk_first_file %&" file "&"
|
||||||
}'
|
}'
|
||||||
}}
|
}}
|
||||||
|
|
||||||
|
define-command -hidden fzf-sk-populate-grep -params 1 %{
|
||||||
|
try %{
|
||||||
|
buffer *grep*
|
||||||
|
} catch %{
|
||||||
|
edit -scratch *grep*
|
||||||
|
set-option buffer filetype grep
|
||||||
|
}
|
||||||
|
evaluate-commands -buffer *grep* %{
|
||||||
|
set-register dquote %arg{1}
|
||||||
|
execute-keys gjPo
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue