Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100755 218 lines (201 sloc) 4.466 kB
c5b5841 @bobthecow Initial commit of git-flow-completion.
authored
1 #!bash
2 #
fd37e37 @bobthecow Added README and LICENSE files, cleaned up documentation inside bash …
authored
3 # git-flow-completion
4 # ===================
5 #
1a6cd16 @bobthecow Fixed capitalization of git-flow
authored
6 # Bash completion support for [git-flow](http://github.com/nvie/gitflow)
fd37e37 @bobthecow Added README and LICENSE files, cleaned up documentation inside bash …
authored
7 #
c5b5841 @bobthecow Initial commit of git-flow-completion.
authored
8 # The contained completion routines provide support for completing:
fd37e37 @bobthecow Added README and LICENSE files, cleaned up documentation inside bash …
authored
9 #
c5b5841 @bobthecow Initial commit of git-flow-completion.
authored
10 # * git-flow init and version
11 # * feature, hotfix and release branches
b2fd9a6 @bobthecow Add autocomplete for 'help' commands and subcommands.
authored
12 # * remote feature, hotfix and release branch names
fd37e37 @bobthecow Added README and LICENSE files, cleaned up documentation inside bash …
authored
13 #
14 #
15 # Installation
16 # ------------
17 #
b20e97a @bobthecow Updated install instructions.
authored
18 # To achieve git-flow completion nirvana:
fd37e37 @bobthecow Added README and LICENSE files, cleaned up documentation inside bash …
authored
19 #
b20e97a @bobthecow Updated install instructions.
authored
20 # 0. Install git-completion.
fd37e37 @bobthecow Added README and LICENSE files, cleaned up documentation inside bash …
authored
21 #
b20e97a @bobthecow Updated install instructions.
authored
22 # 1. Install this file. Either:
fd37e37 @bobthecow Added README and LICENSE files, cleaned up documentation inside bash …
authored
23 #
b20e97a @bobthecow Updated install instructions.
authored
24 # a. Place it in a `bash-completion.d` folder:
fd37e37 @bobthecow Added README and LICENSE files, cleaned up documentation inside bash …
authored
25 #
b20e97a @bobthecow Updated install instructions.
authored
26 # * /etc/bash-completion.d
27 # * /usr/local/etc/bash-completion.d
28 # * ~/bash-completion.d
fd37e37 @bobthecow Added README and LICENSE files, cleaned up documentation inside bash …
authored
29 #
b20e97a @bobthecow Updated install instructions.
authored
30 # b. Or, copy it somewhere (e.g. ~/.git-flow-completion.sh) and put the following line in
31 # your .bashrc:
fd37e37 @bobthecow Added README and LICENSE files, cleaned up documentation inside bash …
authored
32 #
b20e97a @bobthecow Updated install instructions.
authored
33 # source ~/.git-flow-completion.sh
fd37e37 @bobthecow Added README and LICENSE files, cleaned up documentation inside bash …
authored
34 #
3e77edb @bobthecow Apparently I can't count.
authored
35 # 2. If you are using Git < 1.7.1: Edit git-completion.sh and add the following line to the giant
d017360 @bobthecow Update documentation for Git >= 1.7.1 ... We don't have to hack the g…
authored
36 # $command case in _git:
fd37e37 @bobthecow Added README and LICENSE files, cleaned up documentation inside bash …
authored
37 #
38 # flow) _git_flow ;;
39 #
40 #
41 # The Fine Print
42 # --------------
43 #
821fa74 @bobthecow Update copyright date.
authored
44 # Copyright (c) 2011 [Justin Hileman](http://justinhileman.com)
fd37e37 @bobthecow Added README and LICENSE files, cleaned up documentation inside bash …
authored
45 #
46 # Distributed under the [MIT License](http://creativecommons.org/licenses/MIT/)
c5b5841 @bobthecow Initial commit of git-flow-completion.
authored
47
48 _git_flow ()
49 {
88a6987 Added support for completion of 'support' command.
Milan Mitrović authored
50 local subcommands="init feature release hotfix support help version"
91843f8 @bobthecow Revert "Updated __git_find_on_cmdline to use __git_find_subcommand"
authored
51 local subcommand="$(__git_find_on_cmdline "$subcommands")"
c5b5841 @bobthecow Initial commit of git-flow-completion.
authored
52 if [ -z "$subcommand" ]; then
53 __gitcomp "$subcommands"
54 return
55 fi
56
57 case "$subcommand" in
b2fd9a6 @bobthecow Add autocomplete for 'help' commands and subcommands.
authored
58 init)
59 __git_flow_init
60 return
61 ;;
c5b5841 @bobthecow Initial commit of git-flow-completion.
authored
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 ;;
88a6987 Added support for completion of 'support' command.
Milan Mitrović authored
74 support)
75 __git_flow_support
76 return
77 ;;
c5b5841 @bobthecow Initial commit of git-flow-completion.
authored
78 *)
79 COMPREPLY=()
80 ;;
81 esac
82 }
83
b2fd9a6 @bobthecow Add autocomplete for 'help' commands and subcommands.
authored
84 __git_flow_init ()
85 {
86 local subcommands="help"
87 local subcommand="$(__git_find_on_cmdline "$subcommands")"
88 if [ -z "$subcommand" ]; then
89 __gitcomp "$subcommands"
90 return
91 fi
92 }
93
c5b5841 @bobthecow Initial commit of git-flow-completion.
authored
94 __git_flow_feature ()
95 {
b2fd9a6 @bobthecow Add autocomplete for 'help' commands and subcommands.
authored
96 local subcommands="list start finish publish track diff rebase checkout pull help"
91843f8 @bobthecow Revert "Updated __git_find_on_cmdline to use __git_find_subcommand"
authored
97 local subcommand="$(__git_find_on_cmdline "$subcommands")"
c5b5841 @bobthecow Initial commit of git-flow-completion.
authored
98 if [ -z "$subcommand" ]; then
99 __gitcomp "$subcommands"
100 return
101 fi
102
103 case "$subcommand" in
522c026 @bobthecow Add support for new 0.3 feature subcommands (checkout and pull). Upda…
authored
104 pull)
105 __gitcomp "$(__git_remotes)"
106 return
107 ;;
108 checkout|finish|diff|rebase)
5530efe @bobthecow DRYer branch and prefix listing, add support for 'gitflow.origin' con…
authored
109 __gitcomp "$(__git_flow_list_branches 'feature')"
c5b5841 @bobthecow Initial commit of git-flow-completion.
authored
110 return
111 ;;
522c026 @bobthecow Add support for new 0.3 feature subcommands (checkout and pull). Upda…
authored
112 publish)
5530efe @bobthecow DRYer branch and prefix listing, add support for 'gitflow.origin' con…
authored
113 __gitcomp "$(comm -23 <(__git_flow_list_branches 'feature') <(__git_flow_list_remote_branches 'feature'))"
522c026 @bobthecow Add support for new 0.3 feature subcommands (checkout and pull). Upda…
authored
114 return
115 ;;
c5b5841 @bobthecow Initial commit of git-flow-completion.
authored
116 track)
c05e622 @bobthecow Only autocomplete untracked branches for feature/release tracking.
authored
117 __gitcomp "$(comm -23 <(__git_flow_list_remote_branches 'feature') <(__git_flow_list_branches 'feature'))"
c5b5841 @bobthecow Initial commit of git-flow-completion.
authored
118 return
119 ;;
120 *)
121 COMPREPLY=()
122 ;;
123 esac
124 }
125
126 __git_flow_release ()
127 {
a71065b @bobthecow Add support for git-flow 0.4's release and hotfix publish/track subco…
authored
128 local subcommands="list start finish track publish help"
91843f8 @bobthecow Revert "Updated __git_find_on_cmdline to use __git_find_subcommand"
authored
129 local subcommand="$(__git_find_on_cmdline "$subcommands")"
c5b5841 @bobthecow Initial commit of git-flow-completion.
authored
130 if [ -z "$subcommand" ]; then
131 __gitcomp "$subcommands"
132 return
133 fi
134
135 case "$subcommand" in
136 finish)
5530efe @bobthecow DRYer branch and prefix listing, add support for 'gitflow.origin' con…
authored
137 __gitcomp "$(__git_flow_list_branches 'release')"
c5b5841 @bobthecow Initial commit of git-flow-completion.
authored
138 return
139 ;;
a71065b @bobthecow Add support for git-flow 0.4's release and hotfix publish/track subco…
authored
140 publish)
141 __gitcomp "$(comm -23 <(__git_flow_list_branches 'release') <(__git_flow_list_remote_branches 'release'))"
142 return
143 ;;
144 track)
c05e622 @bobthecow Only autocomplete untracked branches for feature/release tracking.
authored
145 __gitcomp "$(comm -23 <(__git_flow_list_remote_branches 'release') <(__git_flow_list_branches 'release'))"
a71065b @bobthecow Add support for git-flow 0.4's release and hotfix publish/track subco…
authored
146 return
147 ;;
c5b5841 @bobthecow Initial commit of git-flow-completion.
authored
148 *)
149 COMPREPLY=()
150 ;;
151 esac
152
153 }
154
155 __git_flow_hotfix ()
156 {
c24e250 @bobthecow Git-flow doesn't track or publish hotfixes.
authored
157 local subcommands="list start finish help"
91843f8 @bobthecow Revert "Updated __git_find_on_cmdline to use __git_find_subcommand"
authored
158 local subcommand="$(__git_find_on_cmdline "$subcommands")"
c5b5841 @bobthecow Initial commit of git-flow-completion.
authored
159 if [ -z "$subcommand" ]; then
160 __gitcomp "$subcommands"
161 return
162 fi
163
164 case "$subcommand" in
165 finish)
5530efe @bobthecow DRYer branch and prefix listing, add support for 'gitflow.origin' con…
authored
166 __gitcomp "$(__git_flow_list_branches 'hotfix')"
c5b5841 @bobthecow Initial commit of git-flow-completion.
authored
167 return
168 ;;
169 *)
170 COMPREPLY=()
171 ;;
172 esac
173 }
174
88a6987 Added support for completion of 'support' command.
Milan Mitrović authored
175 __git_flow_support ()
176 {
177 local subcommands="list start help"
178 local subcommand="$(__git_find_on_cmdline "$subcommands")"
179 if [ -z "$subcommand" ]; then
180 __gitcomp "$subcommands"
181 return
182 fi
183
184 case "$subcommand" in
185 *)
186 COMPREPLY=()
187 ;;
188 esac
189 }
190
5530efe @bobthecow DRYer branch and prefix listing, add support for 'gitflow.origin' con…
authored
191 __git_flow_prefix ()
192 {
193 case "$1" in
194 feature|release|hotfix)
195 git config "gitflow.prefix.$1" 2> /dev/null || echo "$1/"
196 return
197 ;;
198 esac
199 }
200
201 __git_flow_list_branches ()
202 {
203 local prefix="$(__git_flow_prefix $1)"
12cb3bc Sort branch lists so comm does not complain.
Austin Matzko authored
204 git branch 2> /dev/null | tr -d ' |*' | grep "^$prefix" | sed s,^$prefix,, | sort
5530efe @bobthecow DRYer branch and prefix listing, add support for 'gitflow.origin' con…
authored
205 }
206
207 __git_flow_list_remote_branches ()
c5b5841 @bobthecow Initial commit of git-flow-completion.
authored
208 {
5530efe @bobthecow DRYer branch and prefix listing, add support for 'gitflow.origin' con…
authored
209 local prefix="$(__git_flow_prefix $1)"
210 local origin="$(git config gitflow.origin 2> /dev/null || echo "origin")"
12cb3bc Sort branch lists so comm does not complain.
Austin Matzko authored
211 git branch -r 2> /dev/null | sed "s/^ *//g" | grep "^$origin/$prefix" | sed s,^$origin/$prefix,, | sort
f144b1a @bobthecow Temporarily alias __git_find_subcommand to old __git_find_on_cmdline …
authored
212 }
213
91843f8 @bobthecow Revert "Updated __git_find_on_cmdline to use __git_find_subcommand"
authored
214 # alias __git_find_on_cmdline for backwards compatibility
215 if [ -z "`type -t __git_find_on_cmdline`" ]; then
216 alias __git_find_on_cmdline=__git_find_subcommand
217 fi
Something went wrong with that request. Please try again.