]> git.rmz.io Git - dotfiles.git/blob - zsh/plugins/git-flow/git-flow.plugin.zsh
enable extract plugin
[dotfiles.git] / zsh / plugins / git-flow / git-flow.plugin.zsh
1 #!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
23 _git-flow ()
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 '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
72 }
73
74 __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 branch.'
90 'list:List all your release branches. (Alias to `git flow release`)'
91 )
92 _describe -t commands 'git flow release' subcommands
93 _arguments \
94 -v'[Verbose (more) output]'
95 ;;
96
97 (options)
98 case $line[1] in
99
100 (start)
101 _arguments \
102 -F'[Fetch from origin before performing finish]'\
103 ':version:__git_flow_version_list'
104 ;;
105
106 (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 -k'[Keep branch after performing finish]'\
114 -n"[Don't tag this release]"\
115 ':version:__git_flow_version_list'
116 ;;
117
118 *)
119 _arguments \
120 -v'[Verbose (more) output]'
121 ;;
122 esac
123 ;;
124 esac
125 }
126
127 __git-flow-hotfix ()
128 {
129 local curcontext="$curcontext" state line
130 typeset -A opt_args
131
132 _arguments -C \
133 ':command:->command' \
134 '*::options:->options'
135
136 case $state in
137 (command)
138
139 local -a subcommands
140 subcommands=(
141 'start:Start a new hotfix branch.'
142 'finish:Finish a hotfix branch.'
143 'list:List all your hotfix branches. (Alias to `git flow hotfix`)'
144 )
145 _describe -t commands 'git flow hotfix' subcommands
146 _arguments \
147 -v'[Verbose (more) output]'
148 ;;
149
150 (options)
151 case $line[1] in
152
153 (start)
154 _arguments \
155 -F'[Fetch from origin before performing finish]'\
156 ':hotfix:__git_flow_version_list'\
157 ':branch-name:__git_branch_names'
158 ;;
159
160 (finish)
161 _arguments \
162 -F'[Fetch from origin before performing finish]' \
163 -s'[Sign the release tag cryptographically]'\
164 -u'[Use the given GPG-key for the digital signature (implies -s)]'\
165 -m'[Use the given tag message]'\
166 -p'[Push to $ORIGIN after performing finish]'\
167 -k'[Keep branch after performing finish]'\
168 -n"[Don't tag this release]"\
169 ':hotfix:__git_flow_hotfix_list'
170 ;;
171
172 *)
173 _arguments \
174 -v'[Verbose (more) output]'
175 ;;
176 esac
177 ;;
178 esac
179 }
180
181 __git-flow-feature ()
182 {
183 local curcontext="$curcontext" state line
184 typeset -A opt_args
185
186 _arguments -C \
187 ':command:->command' \
188 '*::options:->options'
189
190 case $state in
191 (command)
192
193 local -a subcommands
194 subcommands=(
195 'start:Start a new feature branch.'
196 'finish:Finish a feature branch.'
197 'list:List all your feature branches. (Alias to `git flow feature`)'
198 'publish: publish'
199 'track: track'
200 'diff: diff'
201 'rebase: rebase'
202 'checkout: checkout'
203 'pull: pull'
204 )
205 _describe -t commands 'git flow feature' subcommands
206 _arguments \
207 -v'[Verbose (more) output]'
208 ;;
209
210 (options)
211 case $line[1] in
212
213 (start)
214 _arguments \
215 -F'[Fetch from origin before performing finish]'\
216 ':feature:__git_flow_feature_list'\
217 ':branch-name:__git_branch_names'
218 ;;
219
220 (finish)
221 _arguments \
222 -F'[Fetch from origin before performing finish]' \
223 -r'[Rebase instead of merge]'\
224 -k'[Keep branch after performing finish]'\
225 ':feature:__git_flow_feature_list'
226 ;;
227
228 (publish)
229 _arguments \
230 ':feature:__git_flow_feature_list'\
231 ;;
232
233 (track)
234 _arguments \
235 ':feature:__git_flow_feature_list'\
236 ;;
237
238 (diff)
239 _arguments \
240 ':branch:__git_branch_names'\
241 ;;
242
243 (rebase)
244 _arguments \
245 -i'[Do an interactive rebase]' \
246 ':branch:__git_branch_names'
247 ;;
248
249 (checkout)
250 _arguments \
251 ':branch:__git_flow_feature_list'\
252 ;;
253
254 (pull)
255 _arguments \
256 ':remote:__git_remotes'\
257 ':branch:__git_branch_names'
258 ;;
259
260 *)
261 _arguments \
262 -v'[Verbose (more) output]'
263 ;;
264 esac
265 ;;
266 esac
267 }
268
269 __git_flow_version_list ()
270 {
271 local expl
272 declare -a versions
273
274 versions=(${${(f)"$(_call_program versions git flow release list 2> /dev/null | tr -d ' |*')"}})
275 __git_command_successful || return
276
277 _wanted versions expl 'version' compadd $versions
278 }
279
280 __git_flow_feature_list ()
281 {
282 local expl
283 declare -a features
284
285 features=(${${(f)"$(_call_program features git flow feature list 2> /dev/null | tr -d ' |*')"}})
286 __git_command_successful || return
287
288 _wanted features expl 'feature' compadd $features
289 }
290
291 __git_remotes () {
292 local expl gitdir remotes
293
294 gitdir=$(_call_program gitdir git rev-parse --git-dir 2>/dev/null)
295 __git_command_successful || return
296
297 remotes=(${${(f)"$(_call_program remotes git config --get-regexp '"^remote\..*\.url$"')"}//#(#b)remote.(*).url */$match[1]})
298 __git_command_successful || return
299
300 # TODO: Should combine the two instead of either or.
301 if (( $#remotes > 0 )); then
302 _wanted remotes expl remote compadd $* - $remotes
303 else
304 _wanted remotes expl remote _files $* - -W "($gitdir/remotes)" -g "$gitdir/remotes/*"
305 fi
306 }
307
308 __git_flow_hotfix_list ()
309 {
310 local expl
311 declare -a hotfixes
312
313 hotfixes=(${${(f)"$(_call_program hotfixes git flow hotfix list 2> /dev/null | tr -d ' |*')"}})
314 __git_command_successful || return
315
316 _wanted hotfixes expl 'hotfix' compadd $hotfixes
317 }
318
319 __git_branch_names () {
320 local expl
321 declare -a branch_names
322
323 branch_names=(${${(f)"$(_call_program branchrefs git for-each-ref --format='"%(refname)"' refs/heads 2>/dev/null)"}#refs/heads/})
324 __git_command_successful || return
325
326 _wanted branch-names expl branch-name compadd $* - $branch_names
327 }
328
329 __git_command_successful () {
330 if (( ${#pipestatus:#0} > 0 )); then
331 _message 'not a git repository'
332 return 1
333 fi
334 return 0
335 }
336
337 zstyle ':completion:*:*:git:*' user-commands flow:'description for foo'