forked from raiguard/kak-live-grep
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlive-grep.kak
57 lines (55 loc) · 2.25 KB
/
live-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
declare-option -hidden bool live_grep_select_matches false
declare-option int live_grep_timeout 300
declare-option int live_grep_results_limit 10000
set-face global LiveGrepMatch default+bu
define-command -docstring "start a live grep in the *grep* buffer" live-grep %{
try %{ focus %opt{toolsclient} }
evaluate-commands -try-client %opt{toolsclient} %{
edit -scratch *grep*
set-option buffer filetype grep
try %{
set-option buffer jump_current_line 0
} catch %{
set-option buffer grep_current_line 0
}
set-option window idle_timeout %opt{live_grep_timeout}
prompt -on-change %{
evaluate-commands -save-regs '"' %{
set-register '"' %sh{
if [ -z "$kak_quoted_text" ]; then
exit
fi
result=$($kak_opt_grepcmd "$kak_quoted_text" < /dev/null | tr -d '\r' | head -n $kak_opt_live_grep_results_limit)
echo "$result"
}
execute-keys '<a-;>%<a-;>"_d<a-;>P<a-;>gg'
}
try %{
add-highlighter -override window/grep/live_grep_match regex "%val{text}" 0:LiveGrepMatch
}
} -on-abort %{
remove-hooks window LiveGrepPrompt
remove-highlighter window/grep/live_grep_match
unset-option window idle_timeout
} live-grep: %{
remove-hooks window LiveGrepPrompt
evaluate-commands -save-regs / %sh{
if [ $kak_opt_live_grep_select_matches = true ]; then
query=$(echo "$kak_quoted_text" | sed "s/'/''/g")
printf %s\\n "try %§
execute-keys '%<a-s>s[^:]*:[^:]*:([^:]*:)?<ret>l<a-l>'
set-register / '$query'
execute-keys 's<ret>)'
set-option window live_grep_select_matches false
§"
fi
}
unset-option window idle_timeout
}
hook -group LiveGrepPrompt window RawKey <a-ret> %{
set-option window live_grep_select_matches true
remove-highlighter window/grep/live_grep_match
execute-keys -with-hooks <ret>
}
}
}