blob: db8dccf9db0ca01890ffac4f54331f1f6fdf4395 [file] [log] [blame]
Zifei Tong5eda7412010-08-22 13:22:27 +08001#!zsh
2#
3# Installation
4# ------------
5#
6# To achieve git-flow completion nirvana:
7#
8# 0. Update your zsh's git-completion module to the newest verion.
9# From here. http://zsh.git.sourceforge.net/git/gitweb.cgi?p=zsh/zsh;a=blob_plain;f=Completion/Unix/Command/_git;hb=HEAD
10#
11# 1. Install this file. Either:
12#
13# a. Place it in your .zshrc:
14#
15# b. Or, copy it somewhere (e.g. ~/.git-flow-completion.zsh) and put the following line in
16# your .zshrc:
17#
18# source ~/.git-flow-completion.zsh
19#
20# c. Or, use this file as a oh-my-zsh plugin.
21#
22
Zifei Tong85b504a2010-08-22 10:37:55 +080023_git-flow ()
Zifei Tong4b64ecc2010-08-21 11:20:29 +080024{
Zifei Tong85b504a2010-08-22 10:37:55 +080025 local curcontext="$curcontext" state line
26 typeset -A opt_args
27
28 _arguments -C \
29 ':command:->command' \
30 '*::options:->options'
31
32 case $state in
33 (command)
34
35 local -a subcommands
36 subcommands=(
37 'init:Initialize a new git repo with support for the branching model.'
38 'feature:Manage your feature branches.'
39 'release:Manage your release branches.'
40 'hotfix:Manage your hotfix branches.'
41 'support:Manage your support branches.'
42 'version:Shows version information.'
43 )
44 _describe -t commands 'git flow' subcommands
45 ;;
46
47 (options)
48 case $line[1] in
49
50 (init)
51 _arguments \
52 -f'[Force setting of gitflow branches, even if already configured]'
53 ;;
54
55 (version)
56 ;;
57
58 (hotfix)
59 __git-flow-hotfix
60 ;;
61
62 (release)
63 __git-flow-release
64 ;;
65
66 (feature)
67 __git-flow-feature
68 ;;
69 esac
70 ;;
71 esac
Zifei Tong4b64ecc2010-08-21 11:20:29 +080072}
73
Zifei Tong85b504a2010-08-22 10:37:55 +080074__git-flow-release ()
75{
76 local curcontext="$curcontext" state line
77 typeset -A opt_args
78
79 _arguments -C \
80 ':command:->command' \
81 '*::options:->options'
82
83 case $state in
84 (command)
85
86 local -a subcommands
87 subcommands=(
88 'start:Start a new release branch'
89 'finish:Finish a release branche.'
90 'list:List all your release branches. (Alias to `git flow release`)'
91 )
92 _describe -t commands 'git flow release' subcommands
Zifei Tong9414b222010-08-22 12:41:36 +080093 _arguments \
94 -v'[Verbose (more) output]'
Zifei Tong85b504a2010-08-22 10:37:55 +080095 ;;
96
97 (options)
98 case $line[1] in
99
100 (start)
101 _arguments \
Zifei Tong9414b222010-08-22 12:41:36 +0800102 -F'[Fetch from origin before performing finish]'\
103 ':version:__git_flow_version_list'
Zifei Tong85b504a2010-08-22 10:37:55 +0800104 ;;
105
Zifei Tong9414b222010-08-22 12:41:36 +0800106 (finish)
107 _arguments \
108 -F'[Fetch from origin before performing finish]' \
109 -s'[Sign the release tag cryptographically]'\
110 -u'[Use the given GPG-key for the digital signature (implies -s)]'\
111 -m'[Use the given tag message]'\
112 -p'[Push to $ORIGIN after performing finish]'\
113 ':version:__git_flow_version_list'
Zifei Tong85b504a2010-08-22 10:37:55 +0800114 ;;
Zifei Tong9414b222010-08-22 12:41:36 +0800115
116 *)
117 _arguments \
118 -v'[Verbose (more) output]'
119 ;;
Zifei Tong85b504a2010-08-22 10:37:55 +0800120 esac
121 ;;
122 esac
123}
124
Zifei Tong9414b222010-08-22 12:41:36 +0800125__git-flow-hotfix ()
126{
127 local curcontext="$curcontext" state line
128 typeset -A opt_args
129
130 _arguments -C \
131 ':command:->command' \
132 '*::options:->options'
133
134 case $state in
135 (command)
136
137 local -a subcommands
138 subcommands=(
139 'start:Start a new hotfix branch'
140 'finish:Finish a hotfix branche.'
141 'list:List all your hotfix branches. (Alias to `git flow hotfix`)'
142 )
143 _describe -t commands 'git flow hotfix' subcommands
144 _arguments \
145 -v'[Verbose (more) output]'
146 ;;
147
148 (options)
149 case $line[1] in
150
151 (start)
152 _arguments \
153 -F'[Fetch from origin before performing finish]'\
154 ':hotfix:__git_flow_version_list'\
155 ':branch-name:__git_branch_names'
156 ;;
157
158 (finish)
159 _arguments \
160 -F'[Fetch from origin before performing finish]' \
161 -s'[Sign the release tag cryptographically]'\
162 -u'[Use the given GPG-key for the digital signature (implies -s)]'\
163 -m'[Use the given tag message]'\
164 -p'[Push to $ORIGIN after performing finish]'\
165 ':hotfix:__git_flow_hotfix_list'
166 ;;
167
168 *)
169 _arguments \
170 -v'[Verbose (more) output]'
171 ;;
172 esac
173 ;;
174 esac
175}
176
177__git-flow-feature ()
178{
179 local curcontext="$curcontext" state line
180 typeset -A opt_args
181
182 _arguments -C \
183 ':command:->command' \
184 '*::options:->options'
185
186 case $state in
187 (command)
188
189 local -a subcommands
190 subcommands=(
191 'start:Start a new hotfix branch'
192 'finish:Finish a hotfix branche.'
193 'list:List all your hotfix branches. (Alias to `git flow hotfix`)'
194 'publish: public'
195 'track: track'
196 'diff: diff'
197 'rebase: rebase'
198 'checkout: checkout'
199 'pull: pull'
200 )
201 _describe -t commands 'git flow hotfix' subcommands
202 _arguments \
203 -v'[Verbose (more) output]'
204 ;;
205
206 (options)
207 case $line[1] in
208
209 (start)
210 _arguments \
211 -F'[Fetch from origin before performing finish]'\
212 ':feature:__git_flow_feature_list'\
213 ':branch-name:__git_branch_names'
214 ;;
215
216 (finish)
217 _arguments \
218 -F'[Fetch from origin before performing finish]' \
219 -r'[Rebase instead of merge]'\
220 ':feature:__git_flow_feature_list'
221 ;;
222
223 (publish)
224 _arguments \
225 ':feature:__git_flow_feature_list'\
226 ;;
227
228 (track)
229 _arguments \
230 ':feature:__git_flow_feature_list'\
231 ;;
232
233 (diff)
234 _arguments \
235 ':branch:__git_branch_names'\
236 ;;
237
238 (rebase)
239 _arguments \
240 -i'[Do an interactive rebase]' \
241 ':branch:__git_branch_names'
242 ;;
243
244 (checkout)
245 _arguments \
Vincent Driessenbee82182010-08-22 21:01:01 +0800246 ':branch:__git_flow_feature_list'\
Zifei Tong9414b222010-08-22 12:41:36 +0800247 ;;
248
249 (pull)
250 _arguments \
251 ':remote:__git_remotes'\
252 ':branch:__git_branch_names'
253 ;;
254
255 *)
256 _arguments \
257 -v'[Verbose (more) output]'
258 ;;
259 esac
260 ;;
261 esac
262}
263
264__git_flow_version_list ()
265{
266 local expl
267 declare -a versions
268
Zifei Tongb2667cc2010-08-22 12:48:15 +0800269 versions=(${${(f)"$(_call_program versions git flow release list 2> /dev/null | tr -d ' |*')"}})
Zifei Tong9414b222010-08-22 12:41:36 +0800270 __git_command_successful || return
271
272 _wanted versions expl 'version' compadd $versions
273}
274
275__git_flow_feature_list ()
276{
277 local expl
278 declare -a features
279
280 features=(${${(f)"$(_call_program features git flow feature list 2> /dev/null | tr -d ' |*')"}})
281 __git_command_successful || return
282
283 _wanted features expl 'feature' compadd $features
284}
285
286__git_remotes () {
287 local expl gitdir remotes
288
289 gitdir=$(_call_program gitdir git rev-parse --git-dir 2>/dev/null)
290 __git_command_successful || return
291
Zifei Tong9414b222010-08-22 12:41:36 +0800292 remotes=(${${(f)"$(_call_program remotes git config --get-regexp '"^remote\..*\.url$"')"}//#(#b)remote.(*).url */$match[1]})
293 __git_command_successful || return
294
295 # TODO: Should combine the two instead of either or.
296 if (( $#remotes > 0 )); then
297 _wanted remotes expl remote compadd $* - $remotes
298 else
299 _wanted remotes expl remote _files $* - -W "($gitdir/remotes)" -g "$gitdir/remotes/*"
300 fi
301}
302
303__git_flow_hotfix_list ()
304{
305 local expl
306 declare -a hotfixes
307
Zifei Tongb2667cc2010-08-22 12:48:15 +0800308 hotfixes=(${${(f)"$(_call_program hotfixes git flow hotfix list 2> /dev/null | tr -d ' |*')"}})
Zifei Tong9414b222010-08-22 12:41:36 +0800309 __git_command_successful || return
310
311 _wanted hotfixes expl 'hotfix' compadd $hotfixes
312}
313
314__git_branch_names () {
315 local expl
316 declare -a branch_names
317
318 branch_names=(${${(f)"$(_call_program branchrefs git for-each-ref --format='"%(refname)"' refs/heads 2>/dev/null)"}#refs/heads/})
319 __git_command_successful || return
320
321 _wanted branch-names expl branch-name compadd $* - $branch_names
322}
323
324__git_command_successful () {
325 if (( ${#pipestatus:#0} > 0 )); then
326 _message 'not a git repository'
327 return 1
328 fi
329 return 0
330}
331
Zifei Tong85b504a2010-08-22 10:37:55 +0800332zstyle ':completion:*:*:git:*' user-commands flow:'description for foo'