]> git.rmz.io Git - dotfiles.git/blob - zsh/plugins/git-hubflow/git-hubflow.plugin.zsh
Squashed commit of the following + cleanup afterwards:
[dotfiles.git] / zsh / plugins / git-hubflow / git-hubflow.plugin.zsh
1 #!zsh
2 #
3 # Installation
4 # ------------
5 #
6 # To achieve git-hubflow 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-hubflow-completion.zsh) and put the following line in
16 # your .zshrc:
17 #
18 # source ~/.git-hubflow-completion.zsh
19 #
20 # c. Or, use this file as a oh-my-zsh plugin.
21 #
22
23 _git-hf ()
24 {
25 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 'update:Pull upstream changes down into your master and develop branches.'
43 'version:Shows version information.'
44 )
45 _describe -t commands 'git hf' subcommands
46 ;;
47
48 (options)
49 case $line[1] in
50
51 (init)
52 _arguments \
53 -f'[Force setting of gitflow branches, even if already configured]'
54 ;;
55
56 (version)
57 ;;
58
59 (hotfix)
60 __git-hf-hotfix
61 ;;
62
63 (release)
64 __git-hf-release
65 ;;
66
67 (feature)
68 __git-hf-feature
69 ;;
70 esac
71 ;;
72 esac
73 }
74
75 __git-hf-release ()
76 {
77 local curcontext="$curcontext" state line
78 typeset -A opt_args
79
80 _arguments -C \
81 ':command:->command' \
82 '*::options:->options'
83
84 case $state in
85 (command)
86
87 local -a subcommands
88 subcommands=(
89 'start:Start a new release branch.'
90 'finish:Finish a release branch.'
91 'list:List all your release branches. (Alias to `git hf release`)'
92 'cancel:Cancel release'
93 'push:Push release to github'
94 'pull:Pull release from github'
95 'track:Track release'
96 )
97 _describe -t commands 'git hf release' subcommands
98 _arguments \
99 -v'[Verbose (more) output]'
100 ;;
101
102 (options)
103 case $line[1] in
104
105 (start)
106 _arguments \
107 -F'[Fetch from origin before performing finish]'\
108 ':version:__git_hf_version_list'
109 ;;
110
111 (finish)
112 _arguments \
113 -F'[Fetch from origin before performing finish]' \
114 -s'[Sign the release tag cryptographically]'\
115 -u'[Use the given GPG-key for the digital signature (implies -s)]'\
116 -m'[Use the given tag message]'\
117 -p'[Push to $ORIGIN after performing finish]'\
118 -k'[Keep branch after performing finish]'\
119 -n"[Don't tag this release]"\
120 ':version:__git_hf_version_list'
121 ;;
122
123 *)
124 _arguments \
125 -v'[Verbose (more) output]'
126 ;;
127 esac
128 ;;
129 esac
130 }
131
132 __git-hf-hotfix ()
133 {
134 local curcontext="$curcontext" state line
135 typeset -A opt_args
136
137 _arguments -C \
138 ':command:->command' \
139 '*::options:->options'
140
141 case $state in
142 (command)
143
144 local -a subcommands
145 subcommands=(
146 'start:Start a new hotfix branch.'
147 'finish:Finish a hotfix branch.'
148 'list:List all your hotfix branches. (Alias to `git hf hotfix`)'
149 'publish:Publish the hotfix branch.'
150 'track:Track the hotfix branch.'
151 'pull:Pull the hotfix from github.'
152 'push:Push the hotfix to github.'
153 'cancel:Cancel the hotfix.'
154 )
155 _describe -t commands 'git hf hotfix' subcommands
156 _arguments \
157 -v'[Verbose (more) output]'
158 ;;
159
160 (options)
161 case $line[1] in
162
163 (start)
164 _arguments \
165 -F'[Fetch from origin before performing finish]'\
166 ':hotfix:__git_hf_version_list'\
167 ':branch-name:__git_branch_names'
168 ;;
169
170 (finish)
171 _arguments \
172 -F'[Fetch from origin before performing finish]' \
173 -s'[Sign the release tag cryptographically]'\
174 -u'[Use the given GPG-key for the digital signature (implies -s)]'\
175 -m'[Use the given tag message]'\
176 -p'[Push to $ORIGIN after performing finish]'\
177 -k'[Keep branch after performing finish]'\
178 -n"[Don't tag this release]"\
179 ':hotfix:__git_hf_hotfix_list'
180 ;;
181
182 *)
183 _arguments \
184 -v'[Verbose (more) output]'
185 ;;
186 esac
187 ;;
188 esac
189 }
190
191 __git-hf-feature ()
192 {
193 local curcontext="$curcontext" state line
194 typeset -A opt_args
195
196 _arguments -C \
197 ':command:->command' \
198 '*::options:->options'
199
200 case $state in
201 (command)
202
203 local -a subcommands
204 subcommands=(
205 'list:List all your feature branches. (Alias to `git hf feature`)'
206 'start:Start a new feature branch'
207 'finish:Finish a feature branch'
208 'submit:submit'
209 'track:track'
210 'diff:Diff'
211 'rebase:Rebase feature branch against develop'
212 'checkout:Checkout feature'
213 'pull:Pull feature branch from github'
214 'push:Push feature branch to github'
215 'cancel:Cancel feature'
216 )
217 _describe -t commands 'git hf feature' subcommands
218 _arguments \
219 -v'[Verbose (more) output]'
220 ;;
221
222 (options)
223 case $line[1] in
224
225 (start)
226 _arguments \
227 -F'[Fetch from origin before performing finish]'\
228 ':feature:__git_hf_feature_list'\
229 ':branch-name:__git_branch_names'
230 ;;
231
232 (finish)
233 _arguments \
234 -F'[Fetch from origin before performing finish]' \
235 -r'[Rebase instead of merge]'\
236 ':feature:__git_hf_feature_list'
237 ;;
238
239 (publish)
240 _arguments \
241 ':feature:__git_hf_feature_list'\
242 ;;
243
244 (track)
245 _arguments \
246 ':feature:__git_hf_feature_list'\
247 ;;
248
249 (diff)
250 _arguments \
251 ':branch:__git_branch_names'\
252 ;;
253
254 (rebase)
255 _arguments \
256 -i'[Do an interactive rebase]' \
257 ':branch:__git_branch_names'
258 ;;
259
260 (checkout)
261 _arguments \
262 ':branch:__git_hf_feature_list'\
263 ;;
264
265 (pull)
266 _arguments \
267 ':remote:__git_remotes'\
268 ':branch:__git_branch_names'
269 ;;
270
271 *)
272 _arguments \
273 -v'[Verbose (more) output]'
274 ;;
275 esac
276 ;;
277 esac
278 }
279
280 __git_hf_version_list ()
281 {
282 local expl
283 declare -a versions
284
285 versions=(${${(f)"$(_call_program versions git hf release list 2> /dev/null | tr -d ' |*')"}})
286 __git_command_successful || return
287
288 _wanted versions expl 'version' compadd $versions
289 }
290
291 __git_hf_feature_list ()
292 {
293 local expl
294 declare -a features
295
296 features=(${${(f)"$(_call_program features git hf feature list 2> /dev/null | tr -d ' |*')"}})
297 __git_command_successful || return
298
299 _wanted features expl 'feature' compadd $features
300 }
301
302 __git_remotes () {
303 local expl gitdir remotes
304
305 gitdir=$(_call_program gitdir git rev-parse --git-dir 2>/dev/null)
306 __git_command_successful || return
307
308 remotes=(${${(f)"$(_call_program remotes git config --get-regexp '"^remote\..*\.url$"')"}//#(#b)remote.(*).url */$match[1]})
309 __git_command_successful || return
310
311 # TODO: Should combine the two instead of either or.
312 if (( $#remotes > 0 )); then
313 _wanted remotes expl remote compadd $* - $remotes
314 else
315 _wanted remotes expl remote _files $* - -W "($gitdir/remotes)" -g "$gitdir/remotes/*"
316 fi
317 }
318
319 __git_hf_hotfix_list ()
320 {
321 local expl
322 declare -a hotfixes
323
324 hotfixes=(${${(f)"$(_call_program hotfixes git hf hotfix list 2> /dev/null | tr -d ' |*')"}})
325 __git_command_successful || return
326
327 _wanted hotfixes expl 'hotfix' compadd $hotfixes
328 }
329
330 __git_branch_names () {
331 local expl
332 declare -a branch_names
333
334 branch_names=(${${(f)"$(_call_program branchrefs git for-each-ref --format='"%(refname)"' refs/heads 2>/dev/null)"}#refs/heads/})
335 __git_command_successful || return
336
337 _wanted branch-names expl branch-name compadd $* - $branch_names
338 }
339
340 __git_command_successful () {
341 if (( ${#pipestatus:#0} > 0 )); then
342 _message 'not a git repository'
343 return 1
344 fi
345 return 0
346 }
347
348 zstyle ':completion:*:*:git:*' user-commands flow:'description for foo'