forked from nakamuray/zaw
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ack.zsh
58 lines (49 loc) · 1.37 KB
/
ack.zsh
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
#
# zaw-src-ack
#
# search using ack and open file
#
zmodload zsh/parameter
if ! (( $+commands[ack] )); then
# ack not found
return
fi
autoload -U read-from-minibuffer
function zaw-src-ack() {
local ack_args REPLY f line ret
local -a ack_history
ack_history=( "${(@)${(f)"$(fc -l -n -m "ack --group *" 0 -1)"}#ack --group }" )
function() {
local HISTNO
integer histno=1
# temporary switch to new empty history
fc -p -a
# and add only ack's args to the history
for ack_args in "${(@)ack_history}"; do
print -s -r -- "${ack_args}"
(( histno++ ))
done
HISTNO="${histno}"
read-from-minibuffer "ack --group "
ret=$?
}
if [[ "${ret}" == 0 ]]; then
ack --group "${(Q@)${(z)REPLY}}" | \
while read f; do
while read line; do
if [[ -z "${line}" ]]; then
break
fi
candidates+="${f}"
cand_descriptions+="${f}:${line}"
done
done
print -s -r -- "ack --group ${REPLY}"
actions=("zaw-callback-edit-file" "zaw-callback-append-to-buffer")
act_descriptions=("edit file" "append to edit buffer")
options=("-m")
else
return 1
fi
}
zaw-register-src -n ack zaw-src-ack