Add zsh anything.el plugin
[zsh.git] / .zsh / zaw / sources / git-files.zsh
1 # zaw source for git files
2
3 function zaw-src-git-files-raw() {
4 local ret=0
5 git rev-parse --git-dir >/dev/null 2>&1
6 ret=$?
7 if (( ret != 0 )); then
8 return ret
9 fi
10
11 "$1"
12 ret=$?
13 if (( ret != 0 )); then
14 return ret
15 fi
16
17 actions=(zaw-callback-edit-file zaw-src-git-status-add zaw-src-git-status-add-p zaw-src-git-status-reset zaw-src-git-status-checkout zaw-src-git-status-rm zaw-callback-append-to-buffer)
18 act_descriptions=("edit file" "add" "add -p" "reset" "checkout" "rm" "append to edit buffer")
19 options=(-m -n)
20 return 0
21 }
22
23 function zaw-src-git-files-classify-aux() {
24 local -a as ms ds os
25 : ${(A)as::=${(0)"$(git ls-files $(git rev-parse --show-cdup) -z)"}}
26 : ${(A)ms::=${(0)"$(git ls-files $(git rev-parse --show-cdup) -z -m)"}}
27 if (( ${#ms} == 0 )) || (( ${#ms} == 1 )) && [[ -z "$ms" ]]; then
28 candidates=($as)
29 return 0
30 fi
31
32 if is-at-least 5.0.0 || [[ -n "${ZSH_PATCHLEVEL-}" ]] && \
33 is-at-least 1.5637 "$ZSH_PATCHLEVEL"; then
34 os=(${as:|ms})
35 else
36 os=(${as:#(${(~j.|.)ms})}) # TODO: too slower for large work tree
37 fi
38 candidates=($ms $os)
39
40 : ${(A)ds::=${ms/%/ MODIFIED}}
41 ds+=($os)
42 cand_descriptions=($ds)
43 return 0
44 }
45
46 function zaw-src-git-files-legacy-aux() {
47 : ${(A)candidates::=${(0)"$(git ls-files $(git rev-parse --show-cdup) -z)"}}
48 return 0
49 }
50
51 function zaw-src-git-files-add () {
52 BUFFER="git add $1"
53 zle accept-line
54 }
55
56 {
57 function zaw-src-git-files-register-src() {
58 eval "function $2 () { zaw-src-git-files-raw "$3" }"
59 zaw-register-src -n "$1" "$2"
60 }
61 zaw-src-git-files-register-src git-files zaw-src-git-files zaw-src-git-files-classify-aux
62 zaw-src-git-files-register-src git-files-legacy zaw-src-git-files-legacy{,-aux}
63 } always {
64 unfunction zaw-src-git-files-register-src
65 }