blob: 81b0ee3b8b4e5d746d2cbb28e59ac51aa75c5ecb [file] [log] [blame]
Justin Hilemanc5b58412010-04-26 13:06:11 -04001#!bash
2#
Justin Hilemanfd37e372010-04-26 13:30:18 -04003# git-flow-completion
4# ===================
5#
Justin Hileman1a6cd162010-04-26 13:31:08 -04006# Bash completion support for [git-flow](http://github.com/nvie/gitflow)
Justin Hilemanfd37e372010-04-26 13:30:18 -04007#
Justin Hilemanc5b58412010-04-26 13:06:11 -04008# The contained completion routines provide support for completing:
Justin Hilemanfd37e372010-04-26 13:30:18 -04009#
Justin Hilemanc5b58412010-04-26 13:06:11 -040010# * git-flow init and version
11# * feature, hotfix and release branches
12# * remote feature branch names (for `git-flow feature track`)
Justin Hilemanfd37e372010-04-26 13:30:18 -040013#
14#
15# Installation
16# ------------
17#
Justin Hilemanb20e97a2010-04-26 13:12:01 -040018# To achieve git-flow completion nirvana:
Justin Hilemanfd37e372010-04-26 13:30:18 -040019#
Justin Hilemanb20e97a2010-04-26 13:12:01 -040020# 0. Install git-completion.
Justin Hilemanfd37e372010-04-26 13:30:18 -040021#
Justin Hilemanb20e97a2010-04-26 13:12:01 -040022# 1. Install this file. Either:
Justin Hilemanfd37e372010-04-26 13:30:18 -040023#
Justin Hilemanb20e97a2010-04-26 13:12:01 -040024# a. Place it in a `bash-completion.d` folder:
Justin Hilemanfd37e372010-04-26 13:30:18 -040025#
Justin Hilemanb20e97a2010-04-26 13:12:01 -040026# * /etc/bash-completion.d
27# * /usr/local/etc/bash-completion.d
28# * ~/bash-completion.d
Justin Hilemanfd37e372010-04-26 13:30:18 -040029#
Justin Hilemanb20e97a2010-04-26 13:12:01 -040030# b. Or, copy it somewhere (e.g. ~/.git-flow-completion.sh) and put the following line in
31# your .bashrc:
Justin Hilemanfd37e372010-04-26 13:30:18 -040032#
Justin Hilemanb20e97a2010-04-26 13:12:01 -040033# source ~/.git-flow-completion.sh
Justin Hilemanfd37e372010-04-26 13:30:18 -040034#
Justin Hilemanc5b58412010-04-26 13:06:11 -040035# 3. Edit git-completion.sh and add the following line to the giant $command case in _git:
Justin Hilemanfd37e372010-04-26 13:30:18 -040036#
37# flow) _git_flow ;;
38#
39#
Justin Hilemanc5b58412010-04-26 13:06:11 -040040# 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 Hilemanfd37e372010-04-26 13:30:18 -040042#
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 Hilemanc5b58412010-04-26 13:06:11 -040051
52_git_flow ()
53{
Justin Hilemanfad617d2010-04-26 17:33:11 -040054 local subcommands="init feature release hotfix"
Justin Hilemanc5b58412010-04-26 13:06:11 -040055 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 Hileman5772bc52010-04-26 17:31:35 -040090 finish|publish|diff|rebase)
Justin Hilemanc5b58412010-04-26 13:06:11 -040091 __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 Hileman91891872010-04-26 17:30:53 -0400106 git flow feature list 2> /dev/null
Justin Hilemanc5b58412010-04-26 13:06:11 -0400107}
108
109__git_flow_list_remote_features ()
110{
Justin Hileman91891872010-04-26 17:30:53 -0400111 git branch -r 2> /dev/null | grep 'origin/feature/' | awk '{ sub(/^origin\/feature\//, "", $1); print }'
Justin Hilemanc5b58412010-04-26 13:06:11 -0400112}
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 Hileman91891872010-04-26 17:30:53 -0400137 git flow release list 2> /dev/null
Justin Hilemanc5b58412010-04-26 13:06:11 -0400138}
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 Hileman91891872010-04-26 17:30:53 -0400162 git flow hotfix list 2> /dev/null
Justin Hilemanc5b58412010-04-26 13:06:11 -0400163}