Add zsh anything.el plugin
[zsh.git] / .zsh / zaw / sources / git-status.zsh
1 function zaw-src-git-status() {
2 git rev-parse --git-dir >/dev/null 2>&1
3 if [[ $? == 0 ]]; then
4 local file_list="$(git status --porcelain)"
5 : ${(A)candidates::=${(f)${file_list}}}
6
7 : ${(A)cand_descriptions::=${${(f)${file_list}}/ M /[modified] }}
8 : ${(A)cand_descriptions::=${${(M)cand_descriptions}/AM /[add|modified] }}
9 : ${(A)cand_descriptions::=${${(M)cand_descriptions}/MM /[staged|modified] }}
10 : ${(A)cand_descriptions::=${${(M)cand_descriptions}/M /[staged] }}
11 : ${(A)cand_descriptions::=${${(M)cand_descriptions}/A /[staged(add)] }}
12 : ${(A)cand_descriptions::=${${(M)cand_descriptions}/ D /[deleted] }}
13 : ${(A)cand_descriptions::=${${(M)cand_descriptions}/UU /[conflict] }}
14 : ${(A)cand_descriptions::=${${(M)cand_descriptions}/AA /[conflict] }}
15 : ${(A)cand_descriptions::=${${(M)cand_descriptions}/\?\? /[untracked] }}
16
17 fi
18
19 actions=( \
20 zaw-src-git-status-add \
21 zaw-src-git-status-add-p \
22 zaw-src-git-status-reset \
23 zaw-src-git-status-checkout \
24 zaw-src-git-status-edit \
25 zaw-src-git-status-rm)
26 act_descriptions=( \
27 "add" \
28 "add -p" \
29 "reset" \
30 "checkout" \
31 "edit" \
32 "rm")
33 options=()
34 }
35
36 function zaw-src-git-status-add() {
37 local f_path=${1##?* }
38 local git_base="$(git rev-parse --show-cdup)"
39 BUFFER="git add '$git_base$f_path'"
40 zle accept-line
41 }
42
43 function zaw-src-git-status-add-p() {
44 local f_path=${1##?* }
45 local git_base="$(git rev-parse --show-cdup)"
46 BUFFER="git add -p '$git_base$f_path'"
47 zle accept-line
48 }
49
50 function zaw-src-git-status-reset() {
51 local f_path=${1##?* }
52 local git_base="$(git rev-parse --show-cdup)"
53 BUFFER="git reset '$git_base$f_path'"
54 zle accept-line
55 }
56
57 function zaw-src-git-status-checkout() {
58 local f_path=${1##?* }
59 local git_base="$(git rev-parse --show-cdup)"
60 BUFFER="git checkout '$git_base$f_path'"
61 zle accept-line
62 }
63
64 function zaw-src-git-status-edit() {
65 local f_path=${1##?* }
66 local git_base="$(git rev-parse --show-cdup)"
67 zaw-callback-edit-file "$git_base$f_path"
68 }
69
70 function zaw-src-git-status-rm() {
71 local f_path=${1##?* }
72 local git_base="$(git rev-parse --show-cdup)"
73 BUFFER="git rm '$git_base$f_path'"
74 zle accept-line
75 }
76
77 zaw-register-src -n git-status zaw-src-git-status