initial
[zsh.git] / .zsh / plugins / git-extras.plugin.zsh
1 #compdef git
2 # ------------------------------------------------------------------------------
3 # Description
4 # -----------
5 #
6 # Completion script for git-extras (http://github.com/visionmedia/git-extras).
7 #
8 # ------------------------------------------------------------------------------
9 # Authors
10 # -------
11 #
12 # * Alexis GRIMALDI (https://github.com/agrimaldi)
13 #
14 # ------------------------------------------------------------------------------
15 # Inspirations
16 # -----------
17 #
18 # * git-extras (http://github.com/visionmedia/git-extras)
19 # * git-flow-completion (http://github.com/bobthecow/git-flow-completion)
20 #
21 # ------------------------------------------------------------------------------
22
23
24 __git_command_successful () {
25 if (( ${#pipestatus:#0} > 0 )); then
26 _message 'not a git repository'
27 return 1
28 fi
29 return 0
30 }
31
32
33 __git_tag_names() {
34 local expl
35 declare -a tag_names
36 tag_names=(${${(f)"$(_call_program branchrefs git for-each-ref --format='"%(refname)"' refs/tags 2>/dev/null)"}#refs/tags/})
37 __git_command_successful || return
38 _wanted tag-names expl tag-name compadd $* - $tag_names
39 }
40
41
42 __git_branch_names() {
43 local expl
44 declare -a branch_names
45 branch_names=(${${(f)"$(_call_program branchrefs git for-each-ref --format='"%(refname)"' refs/heads 2>/dev/null)"}#refs/heads/})
46 __git_command_successful || return
47 _wanted branch-names expl branch-name compadd $* - $branch_names
48 }
49
50
51 __git_feature_branch_names() {
52 local expl
53 declare -a branch_names
54 branch_names=(${${(f)"$(_call_program branchrefs git for-each-ref --format='"%(refname)"' refs/heads/feature 2>/dev/null)"}#refs/heads/feature/})
55 __git_command_successful || return
56 _wanted branch-names expl branch-name compadd $* - $branch_names
57 }
58
59
60 __git_refactor_branch_names() {
61 local expl
62 declare -a branch_names
63 branch_names=(${${(f)"$(_call_program branchrefs git for-each-ref --format='"%(refname)"' refs/heads/refactor 2>/dev/null)"}#refs/heads/refactor/})
64 __git_command_successful || return
65 _wanted branch-names expl branch-name compadd $* - $branch_names
66 }
67
68
69 __git_bug_branch_names() {
70 local expl
71 declare -a branch_names
72 branch_names=(${${(f)"$(_call_program branchrefs git for-each-ref --format='"%(refname)"' refs/heads/bug 2>/dev/null)"}#refs/heads/bug/})
73 __git_command_successful || return
74 _wanted branch-names expl branch-name compadd $* - $branch_names
75 }
76
77
78 __git_submodule_names() {
79 local expl
80 declare -a submodule_names
81 submodule_names=(${(f)"$(_call_program branchrefs git submodule status | awk '{print $2}')"})
82 __git_command_successful || return
83 _wanted submodule-names expl submodule-name compadd $* - $submodule_names
84 }
85
86
87 __git_author_names() {
88 local expl
89 declare -a author_names
90 author_names=(${(f)"$(_call_program branchrefs git log --format='%aN' | sort -u)"})
91 __git_command_successful || return
92 _wanted author-names expl author-name compadd $* - $author_names
93 }
94
95
96 _git-changelog() {
97 _arguments \
98 '(-l --list)'{-l,--list}'[list commits]' \
99 }
100
101
102 _git-effort() {
103 _arguments \
104 '--above[ignore file with less than x commits]' \
105 }
106
107
108 _git-contrib() {
109 _arguments \
110 ':author:__git_author_names'
111 }
112
113
114 _git-count() {
115 _arguments \
116 '--all[detailed commit count]'
117 }
118
119
120 _git-delete-branch() {
121 _arguments \
122 ':branch-name:__git_branch_names'
123 }
124
125
126 _git-delete-submodule() {
127 _arguments \
128 ':submodule-name:__git_submodule_names'
129 }
130
131
132 _git-delete-tag() {
133 _arguments \
134 ':tag-name:__git_tag_names'
135 }
136
137
138 _git-extras() {
139 local curcontext=$curcontext state line ret=1
140 declare -A opt_args
141
142 _arguments -C \
143 ': :->command' \
144 '*:: :->option-or-argument' && ret=0
145
146 case $state in
147 (command)
148 declare -a commands
149 commands=(
150 'update:update git-extras'
151 )
152 _describe -t commands command commands && ret=0
153 ;;
154 esac
155
156 _arguments \
157 '(-v --version)'{-v,--version}'[show current version]' \
158 }
159
160
161 _git-graft() {
162 _arguments \
163 ':src-branch-name:__git_branch_names' \
164 ':dest-branch-name:__git_branch_names'
165 }
166
167
168 _git-squash() {
169 _arguments \
170 ':branch-name:__git_branch_names'
171 }
172
173
174 _git-feature() {
175 local curcontext=$curcontext state line ret=1
176 declare -A opt_args
177
178 _arguments -C \
179 ': :->command' \
180 '*:: :->option-or-argument' && ret=0
181
182 case $state in
183 (command)
184 declare -a commands
185 commands=(
186 'finish:merge feature into the current branch'
187 )
188 _describe -t commands command commands && ret=0
189 ;;
190 (option-or-argument)
191 curcontext=${curcontext%:*}-$line[1]:
192 case $line[1] in
193 (finish)
194 _arguments -C \
195 ':branch-name:__git_feature_branch_names'
196 ;;
197 esac
198 esac
199 }
200
201
202 _git-refactor() {
203 local curcontext=$curcontext state line ret=1
204 declare -A opt_args
205
206 _arguments -C \
207 ': :->command' \
208 '*:: :->option-or-argument' && ret=0
209
210 case $state in
211 (command)
212 declare -a commands
213 commands=(
214 'finish:merge refactor into the current branch'
215 )
216 _describe -t commands command commands && ret=0
217 ;;
218 (option-or-argument)
219 curcontext=${curcontext%:*}-$line[1]:
220 case $line[1] in
221 (finish)
222 _arguments -C \
223 ':branch-name:__git_refactor_branch_names'
224 ;;
225 esac
226 esac
227 }
228
229
230 _git-bug() {
231 local curcontext=$curcontext state line ret=1
232 declare -A opt_args
233
234 _arguments -C \
235 ': :->command' \
236 '*:: :->option-or-argument' && ret=0
237
238 case $state in
239 (command)
240 declare -a commands
241 commands=(
242 'finish:merge bug into the current branch'
243 )
244 _describe -t commands command commands && ret=0
245 ;;
246 (option-or-argument)
247 curcontext=${curcontext%:*}-$line[1]:
248 case $line[1] in
249 (finish)
250 _arguments -C \
251 ':branch-name:__git_bug_branch_names'
252 ;;
253 esac
254 esac
255 }
256
257
258 zstyle ':completion:*:*:git:*' user-commands \
259 changelog:'populate changelog file with commits since the previous tag' \
260 contrib:'display author contributions' \
261 count:'count commits' \
262 delete-branch:'delete local and remote branch' \
263 delete-submodule:'delete submodule' \
264 delete-tag:'delete local and remote tag' \
265 extras:'git-extras' \
266 graft:'merge commits from source branch to destination branch' \
267 squash:'merge commits from source branch into the current one as a single commit' \
268 feature:'create a feature branch' \
269 refactor:'create a refactor branch' \
270 bug:'create a bug branch' \
271 summary:'repository summary' \
272 effort:'display effort statistics' \
273 repl:'read-eval-print-loop' \
274 commits-since:'list commits since a given date' \
275 release:'release commit with the given tag' \
276 alias:'define, search and show aliases' \
277 ignore:'add patterns to .gitignore' \
278 info:'show info about the repository' \
279 create-branch:'create local and remote branch' \
280 fresh-branch:'create empty local branch' \
281 undo:'remove the latest commit' \
282 setup:'setup a git repository' \
283 touch:'one step creation of new files' \
284 obliterate:'Completely remove a file from the repository, including past commits and tags' \
285 local-commits:'list unpushed commits on the local branch' \