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