This repository has been archived by the owner on Oct 23, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 33
/
sk-grep.kak
68 lines (59 loc) · 2.82 KB
/
sk-grep.kak
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# Author: Andrey Listopadov
# Module running interactive grep with skim for fzf.kak
# https://github.com/andreyorst/fzf.kak
hook global ModuleLoaded fzf %§
evaluate-commands %sh{
if [ -n "$(command -v sk)" ]; then
printf "%s\n" "echo -debug -- %{skim support is deprecated and will be removed in future release, use fzf-grep instead}"
printf "%s\n" "map global fzf -docstring %{Interactive grep with skim} '<a-g>' '<esc>: require-module fzf-sk-grep; fzf-sk-grep<ret>'"
fi
}
§
provide-module fzf-sk-grep %§
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'
declare-option -hidden str fzf_sk_first_file ''
define-command -hidden fzf-sk-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
<ret>: open search result in new buffer.
${kak_opt_fzf_window_map:-ctrl-w}: open search result in new terminal"
[ -n "${kak_client_env_TMUX:-}" ] && tmux_keybindings="
${kak_opt_fzf_horizontal_map:-ctrl-s}: open search result in horizontal split
${kak_opt_fzf_vertical_map:-ctrl-v}: open search result in vertical split"
printf "%s\n" "echo -markup %{{Information}skim support is deprecated and will be removed in future release, use fzf-grep instead}"
printf "%s\n" "info -title '${title}' '${message}${tmux_keybindings}'"
[ -n "${kak_client_env_TMUX}" ] && additional_flags="--expect ${kak_opt_fzf_vertical_map:-ctrl-v} --expect ${kak_opt_fzf_horizontal_map:-ctrl-s}"
printf "%s\n" "fzf -kak-cmd %{fzf-sk-grep-handler} -fzf-impl %{sk --ansi -m -i -c '${kak_opt_fzf_sk_grep_command:-} {}'} -fzf-args %{--expect ${kak_opt_fzf_window_map:-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{
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&"
print "set-option global fzf_sk_first_file %&" file "&"
}'
}
fzf-sk-populate-grep %arg{1}
}
define-command -hidden fzf-sk-populate-grep -params 1 %{
try %{
buffer *grep*
} catch %{
edit -scratch *grep*
set-option buffer filetype grep
}
evaluate-commands -save-regs '"' -buffer *grep* %{
set-register dquote %arg{1}
execute-keys gjPo
}
}
§