2019-03-02 19:15:33 +00:00
|
|
|
# ╭─────────────╥────────────────────────╮
|
|
|
|
# │ Author: ║ File: │
|
|
|
|
# │ Andrey Orst ║ sk-grep.kak │
|
|
|
|
# ╞═════════════╩════════════════════════╡
|
|
|
|
# │ Module running interactive grep with │
|
|
|
|
# │ ski for fzf.kak │
|
|
|
|
# ╞══════════════════════════════════════╡
|
|
|
|
# │ GitHub.com/andreyorst/fzf.kak │
|
|
|
|
# ╰──────────────────────────────────────╯
|
|
|
|
|
2019-03-03 18:31:23 +00:00
|
|
|
declare-option -docstring "what command to use to provide list of grep search matches.
|
2019-03-03 18:50:20 +00:00
|
|
|
Grep output must follow the format of 'filename:line-number:text'
|
2019-03-03 18:31:23 +00:00
|
|
|
|
2019-03-03 18:50:20 +00:00
|
|
|
Default value:
|
|
|
|
grep -RHn" \
|
|
|
|
str fzf_sk_grep_command 'grep -RHn'
|
2019-03-02 19:15:33 +00:00
|
|
|
|
2019-03-26 17:34:01 +00:00
|
|
|
try %{ declare-user-mode fzf }
|
|
|
|
|
2019-03-02 19:15:33 +00:00
|
|
|
evaluate-commands %sh{
|
|
|
|
if [ -n "$(command -v sk)" ]; then
|
2019-03-27 06:53:38 +00:00
|
|
|
printf "%s\n" "map global fzf -docstring %{Interactive grep with skim} 'g' '<esc>: fzf-sk-grep<ret>'"
|
2019-03-02 19:15:33 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2019-03-27 06:53:38 +00:00
|
|
|
define-command -hidden fzf-sk-grep %{ evaluate-commands %sh{
|
2019-03-02 19:15:33 +00:00
|
|
|
if [ -z "$(command -v sk)" ]; then
|
|
|
|
printf "%s\n" "echo -markup %{{Information}skim required to run this command}"
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
title="skim interactive grep"
|
2019-03-03 18:31:23 +00:00
|
|
|
message="Interactively grep pattern from current directory
|
|
|
|
<ret>: open search result in new buffer.
|
2019-03-28 05:38:38 +00:00
|
|
|
<c-w>: open search result in new terminal"
|
2019-03-03 18:31:23 +00:00
|
|
|
[ ! -z "${kak_client_env_TMUX}" ] && tmux_keybindings="
|
|
|
|
<c-s>: open search result in horizontal split
|
|
|
|
<c-v>: 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"
|
2019-03-27 08:35:54 +00:00
|
|
|
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}"
|
2019-03-02 19:15:33 +00:00
|
|
|
}}
|
|
|
|
|
2019-03-26 19:11:00 +00:00
|
|
|
define-command -hidden fzf-sk-grep-handler -params 1 %{ evaluate-commands %sh{
|
2019-03-03 18:31:23 +00:00
|
|
|
printf "%s\n" "$1" | awk '{
|
|
|
|
file = $0; sub(/:.*/, "", file); gsub("&", "&&", file);
|
2019-03-03 18:50:20 +00:00
|
|
|
line = $0; sub(/[^:]+:/, "", line); sub(/:.*/, "", line)
|
|
|
|
print "edit -existing %&" file "&; execute-keys %&" line "gxvc&";
|
2019-03-03 18:31:23 +00:00
|
|
|
}'
|
2019-03-02 19:15:33 +00:00
|
|
|
}}
|
|
|
|
|