Add zsh anything.el plugin
[zsh.git] / .zsh / zaw / sources / searcher.zsh
1 # zaw source for ack/ag searcher
2
3 autoload -U read-from-minibuffer
4
5 typeset -g ZAW_SEARCHER_CMD
6
7 if (( $+commands[ag] )); then
8 ZAW_SEARCHER_CMD="ag"
9 elif (( $+commands[ack-grep] )); then
10 ZAW_SEARCHER_CMD="ack-grep"
11 elif (( $+commands[ack] )); then
12 ZAW_SEARCHER_CMD="ack"
13 else
14 # ack/ag are not found, and disable this source
15 return
16 fi
17
18 function zaw-src-searcher() {
19 local buf
20 read-from-minibuffer "${ZAW_SEARCHER_CMD} "
21 buf=$($ZAW_SEARCHER_CMD ${(Q@)${(z)REPLY}})
22 if [[ $? != 0 ]]; then
23 return 1
24 fi
25 : ${(A)candidates::=${(f)buf}}
26 : ${(A)cand_descriptions::=${(f)buf}}
27 actions=(\
28 zaw-src-searcher-edit \
29 )
30 act_descriptions=(\
31 "Edit" \
32 )
33 }
34
35 function zaw-src-searcher-edit () {
36 local filename=${1%%:*}
37 local line=${${1#*:}%%:*}
38 if [[ -z $ZAW_EDITOR_JUMP_PARAM ]]; then
39 ZAW_EDITOR_JUMP_PARAM="+%LINE% %FILE%"
40 fi
41 BUFFER="${EDITOR} ${${ZAW_EDITOR_JUMP_PARAM/\%LINE\%/$line}/\%FILE\%/$filename}"
42 zle accept-line
43 }
44
45 zaw-register-src -n searcher zaw-src-searcher