Zifei Tong | 5eda741 | 2010-08-22 13:22:27 +0800 | [diff] [blame] | 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 | |
Zifei Tong | 85b504a | 2010-08-22 10:37:55 +0800 | [diff] [blame] | 23 | _git-flow () |
Zifei Tong | 4b64ecc | 2010-08-21 11:20:29 +0800 | [diff] [blame] | 24 | { |
Zifei Tong | 85b504a | 2010-08-22 10:37:55 +0800 | [diff] [blame] | 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 |
Zifei Tong | 4b64ecc | 2010-08-21 11:20:29 +0800 | [diff] [blame] | 72 | } |
| 73 | |
Zifei Tong | 85b504a | 2010-08-22 10:37:55 +0800 | [diff] [blame] | 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 branche.' |
| 90 | 'list:List all your release branches. (Alias to `git flow release`)' |
| 91 | ) |
| 92 | _describe -t commands 'git flow release' subcommands |
Zifei Tong | 9414b22 | 2010-08-22 12:41:36 +0800 | [diff] [blame] | 93 | _arguments \ |
| 94 | -v'[Verbose (more) output]' |
Zifei Tong | 85b504a | 2010-08-22 10:37:55 +0800 | [diff] [blame] | 95 | ;; |
| 96 | |
| 97 | (options) |
| 98 | case $line[1] in |
| 99 | |
| 100 | (start) |
| 101 | _arguments \ |
Zifei Tong | 9414b22 | 2010-08-22 12:41:36 +0800 | [diff] [blame] | 102 | -F'[Fetch from origin before performing finish]'\ |
| 103 | ':version:__git_flow_version_list' |
Zifei Tong | 85b504a | 2010-08-22 10:37:55 +0800 | [diff] [blame] | 104 | ;; |
| 105 | |
Zifei Tong | 9414b22 | 2010-08-22 12:41:36 +0800 | [diff] [blame] | 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 | ':version:__git_flow_version_list' |
Zifei Tong | 85b504a | 2010-08-22 10:37:55 +0800 | [diff] [blame] | 114 | ;; |
Zifei Tong | 9414b22 | 2010-08-22 12:41:36 +0800 | [diff] [blame] | 115 | |
| 116 | *) |
| 117 | _arguments \ |
| 118 | -v'[Verbose (more) output]' |
| 119 | ;; |
Zifei Tong | 85b504a | 2010-08-22 10:37:55 +0800 | [diff] [blame] | 120 | esac |
| 121 | ;; |
| 122 | esac |
| 123 | } |
| 124 | |
Zifei Tong | 9414b22 | 2010-08-22 12:41:36 +0800 | [diff] [blame] | 125 | __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 Driessen | bee8218 | 2010-08-22 21:01:01 +0800 | [diff] [blame] | 246 | ':branch:__git_flow_feature_list'\ |
Zifei Tong | 9414b22 | 2010-08-22 12:41:36 +0800 | [diff] [blame] | 247 | ;; |
| 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 Tong | b2667cc | 2010-08-22 12:48:15 +0800 | [diff] [blame] | 269 | versions=(${${(f)"$(_call_program versions git flow release list 2> /dev/null | tr -d ' |*')"}}) |
Zifei Tong | 9414b22 | 2010-08-22 12:41:36 +0800 | [diff] [blame] | 270 | __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 Tong | 9414b22 | 2010-08-22 12:41:36 +0800 | [diff] [blame] | 292 | 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 Tong | b2667cc | 2010-08-22 12:48:15 +0800 | [diff] [blame] | 308 | hotfixes=(${${(f)"$(_call_program hotfixes git flow hotfix list 2> /dev/null | tr -d ' |*')"}}) |
Zifei Tong | 9414b22 | 2010-08-22 12:41:36 +0800 | [diff] [blame] | 309 | __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 Tong | 85b504a | 2010-08-22 10:37:55 +0800 | [diff] [blame] | 332 | zstyle ':completion:*:*:git:*' user-commands flow:'description for foo' |