Justin Hileman | c5b5841 | 2010-04-26 13:06:11 -0400 | [diff] [blame] | 1 | #!bash |
| 2 | # |
Justin Hileman | fd37e37 | 2010-04-26 13:30:18 -0400 | [diff] [blame] | 3 | # git-flow-completion |
| 4 | # =================== |
| 5 | # |
Justin Hileman | 1a6cd16 | 2010-04-26 13:31:08 -0400 | [diff] [blame] | 6 | # Bash completion support for [git-flow](http://github.com/nvie/gitflow) |
Justin Hileman | fd37e37 | 2010-04-26 13:30:18 -0400 | [diff] [blame] | 7 | # |
Justin Hileman | c5b5841 | 2010-04-26 13:06:11 -0400 | [diff] [blame] | 8 | # The contained completion routines provide support for completing: |
Justin Hileman | fd37e37 | 2010-04-26 13:30:18 -0400 | [diff] [blame] | 9 | # |
Justin Hileman | c5b5841 | 2010-04-26 13:06:11 -0400 | [diff] [blame] | 10 | # * git-flow init and version |
| 11 | # * feature, hotfix and release branches |
| 12 | # * remote feature branch names (for `git-flow feature track`) |
Justin Hileman | fd37e37 | 2010-04-26 13:30:18 -0400 | [diff] [blame] | 13 | # |
| 14 | # |
| 15 | # Installation |
| 16 | # ------------ |
| 17 | # |
Justin Hileman | b20e97a | 2010-04-26 13:12:01 -0400 | [diff] [blame] | 18 | # To achieve git-flow completion nirvana: |
Justin Hileman | fd37e37 | 2010-04-26 13:30:18 -0400 | [diff] [blame] | 19 | # |
Justin Hileman | b20e97a | 2010-04-26 13:12:01 -0400 | [diff] [blame] | 20 | # 0. Install git-completion. |
Justin Hileman | fd37e37 | 2010-04-26 13:30:18 -0400 | [diff] [blame] | 21 | # |
Justin Hileman | b20e97a | 2010-04-26 13:12:01 -0400 | [diff] [blame] | 22 | # 1. Install this file. Either: |
Justin Hileman | fd37e37 | 2010-04-26 13:30:18 -0400 | [diff] [blame] | 23 | # |
Justin Hileman | b20e97a | 2010-04-26 13:12:01 -0400 | [diff] [blame] | 24 | # a. Place it in a `bash-completion.d` folder: |
Justin Hileman | fd37e37 | 2010-04-26 13:30:18 -0400 | [diff] [blame] | 25 | # |
Justin Hileman | b20e97a | 2010-04-26 13:12:01 -0400 | [diff] [blame] | 26 | # * /etc/bash-completion.d |
| 27 | # * /usr/local/etc/bash-completion.d |
| 28 | # * ~/bash-completion.d |
Justin Hileman | fd37e37 | 2010-04-26 13:30:18 -0400 | [diff] [blame] | 29 | # |
Justin Hileman | b20e97a | 2010-04-26 13:12:01 -0400 | [diff] [blame] | 30 | # b. Or, copy it somewhere (e.g. ~/.git-flow-completion.sh) and put the following line in |
| 31 | # your .bashrc: |
Justin Hileman | fd37e37 | 2010-04-26 13:30:18 -0400 | [diff] [blame] | 32 | # |
Justin Hileman | b20e97a | 2010-04-26 13:12:01 -0400 | [diff] [blame] | 33 | # source ~/.git-flow-completion.sh |
Justin Hileman | fd37e37 | 2010-04-26 13:30:18 -0400 | [diff] [blame] | 34 | # |
Justin Hileman | c5b5841 | 2010-04-26 13:06:11 -0400 | [diff] [blame] | 35 | # 3. Edit git-completion.sh and add the following line to the giant $command case in _git: |
Justin Hileman | fd37e37 | 2010-04-26 13:30:18 -0400 | [diff] [blame] | 36 | # |
| 37 | # flow) _git_flow ;; |
| 38 | # |
| 39 | # |
Justin Hileman | c5b5841 | 2010-04-26 13:06:11 -0400 | [diff] [blame] | 40 | # Requirement 3 will go away as soon as I figure out how to properly (and predictably) hijack |
| 41 | # the `complete -F` ownership for `git` without breaking regular `git-completion`... |
Justin Hileman | fd37e37 | 2010-04-26 13:30:18 -0400 | [diff] [blame] | 42 | # |
| 43 | # |
| 44 | # |
| 45 | # The Fine Print |
| 46 | # -------------- |
| 47 | # |
| 48 | # Copyright (c) 2010 [Justin Hileman](http://justinhileman.com) |
| 49 | # |
| 50 | # Distributed under the [MIT License](http://creativecommons.org/licenses/MIT/) |
Justin Hileman | c5b5841 | 2010-04-26 13:06:11 -0400 | [diff] [blame] | 51 | |
| 52 | _git_flow () |
| 53 | { |
Justin Hileman | fad617d | 2010-04-26 17:33:11 -0400 | [diff] [blame] | 54 | local subcommands="init feature release hotfix" |
Justin Hileman | c5b5841 | 2010-04-26 13:06:11 -0400 | [diff] [blame] | 55 | local subcommand="$(__git_find_on_cmdline "$subcommands")" |
| 56 | if [ -z "$subcommand" ]; then |
| 57 | __gitcomp "$subcommands" |
| 58 | return |
| 59 | fi |
| 60 | |
| 61 | case "$subcommand" in |
| 62 | feature) |
| 63 | __git_flow_feature |
| 64 | return |
| 65 | ;; |
| 66 | release) |
| 67 | __git_flow_release |
| 68 | return |
| 69 | ;; |
| 70 | hotfix) |
| 71 | __git_flow_hotfix |
| 72 | return |
| 73 | ;; |
| 74 | *) |
| 75 | COMPREPLY=() |
| 76 | ;; |
| 77 | esac |
| 78 | } |
| 79 | |
| 80 | __git_flow_feature () |
| 81 | { |
| 82 | local subcommands="list start finish publish track diff rebase" |
| 83 | local subcommand="$(__git_find_on_cmdline "$subcommands")" |
| 84 | if [ -z "$subcommand" ]; then |
| 85 | __gitcomp "$subcommands" |
| 86 | return |
| 87 | fi |
| 88 | |
| 89 | case "$subcommand" in |
Justin Hileman | 5772bc5 | 2010-04-26 17:31:35 -0400 | [diff] [blame] | 90 | finish|publish|diff|rebase) |
Justin Hileman | c5b5841 | 2010-04-26 13:06:11 -0400 | [diff] [blame] | 91 | __gitcomp "$(__git_flow_list_features)" |
| 92 | return |
| 93 | ;; |
| 94 | track) |
| 95 | __gitcomp "$(__git_flow_list_remote_features)" |
| 96 | return |
| 97 | ;; |
| 98 | *) |
| 99 | COMPREPLY=() |
| 100 | ;; |
| 101 | esac |
| 102 | } |
| 103 | |
| 104 | __git_flow_list_features () |
| 105 | { |
Justin Hileman | 9189187 | 2010-04-26 17:30:53 -0400 | [diff] [blame] | 106 | git flow feature list 2> /dev/null |
Justin Hileman | c5b5841 | 2010-04-26 13:06:11 -0400 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | __git_flow_list_remote_features () |
| 110 | { |
Justin Hileman | 9189187 | 2010-04-26 17:30:53 -0400 | [diff] [blame] | 111 | git branch -r 2> /dev/null | grep 'origin/feature/' | awk '{ sub(/^origin\/feature\//, "", $1); print }' |
Justin Hileman | c5b5841 | 2010-04-26 13:06:11 -0400 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | __git_flow_release () |
| 115 | { |
| 116 | local subcommands="list start finish" |
| 117 | local subcommand="$(__git_find_on_cmdline "$subcommands")" |
| 118 | if [ -z "$subcommand" ]; then |
| 119 | __gitcomp "$subcommands" |
| 120 | return |
| 121 | fi |
| 122 | |
| 123 | case "$subcommand" in |
| 124 | finish) |
| 125 | __gitcomp "$(__git_flow_list_releases)" |
| 126 | return |
| 127 | ;; |
| 128 | *) |
| 129 | COMPREPLY=() |
| 130 | ;; |
| 131 | esac |
| 132 | |
| 133 | } |
| 134 | |
| 135 | __git_flow_list_releases () |
| 136 | { |
Justin Hileman | 9189187 | 2010-04-26 17:30:53 -0400 | [diff] [blame] | 137 | git flow release list 2> /dev/null |
Justin Hileman | c5b5841 | 2010-04-26 13:06:11 -0400 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | __git_flow_hotfix () |
| 141 | { |
| 142 | local subcommands="list start finish" |
| 143 | local subcommand="$(__git_find_on_cmdline "$subcommands")" |
| 144 | if [ -z "$subcommand" ]; then |
| 145 | __gitcomp "$subcommands" |
| 146 | return |
| 147 | fi |
| 148 | |
| 149 | case "$subcommand" in |
| 150 | finish) |
| 151 | __gitcomp "$(__git_flow_list_hotfixes)" |
| 152 | return |
| 153 | ;; |
| 154 | *) |
| 155 | COMPREPLY=() |
| 156 | ;; |
| 157 | esac |
| 158 | } |
| 159 | |
| 160 | __git_flow_list_hotfixes () |
| 161 | { |
Justin Hileman | 9189187 | 2010-04-26 17:30:53 -0400 | [diff] [blame] | 162 | git flow hotfix list 2> /dev/null |
Justin Hileman | c5b5841 | 2010-04-26 13:06:11 -0400 | [diff] [blame] | 163 | } |