blob: 6a32e32e43ea72ebb36863826b3491df4e47611d [file] [log] [blame]
Justin Hileman2fdbd742012-07-24 11:51:26 -07001#!fish
2#
3# git-flow-completion
4# ===================
5#
6# Fish completion support for [git-flow](http://github.com/nvie/gitflow)
7#
8# The contained completion routines provide support for completing:
9#
10# * git-flow init and version
11# * feature, hotfix and release branches
12# * remote feature, hotfix and release branch names
13#
14#
15# Installation
16# ------------
17#
18# To achieve git-flow completion nirvana:
19#
20# 1. Install this file it in your `~/.config/fish/completions` folder.
21#
22# 2. (If your shared fish completions aren't in `/usr/share/...` or `/usr/local/share/...`)
23# Edit the first line
24#
25#
26# The Fine Print
27# --------------
28#
29# Copyright (c) 2012 [Justin Hileman](http://justinhileman.com)
30#
31# Distributed under the [MIT License](http://creativecommons.org/licenses/MIT/)
32
33for prefix in /usr /usr/local
34 if test -f $prefix/share/fish/completions/git.fish
35 . $prefix/share/fish/completions/git.fish
36 break
37 end
38end
39
40if not functions -q __fish_git_branches
41 echo \nError: git completion not found >&2
42 exit
43end
44
45## Support functions
46
47function __fish_git_flow_using_command
48 set cmd (commandline -opc)
49 set subcommands 'flow' $argv
50 if [ (count $cmd) = (math (count $subcommands) + 1) ]
51 for i in (seq (count $subcommands))
52 if not test $subcommands[$i] = $cmd[(math $i + 1)]
53 return 1
54 end
55 end
56 return 0
57 end
58 return 1
59end
60
61function __fish_git_flow_prefix
62 git config "gitflow.prefix.$argv[1]" 2> /dev/null; or echo "$argv[1]/"
63end
64
65function __fish_git_flow_branches
66 set prefix (__fish_git_flow_prefix $argv[1])
67 __fish_git_branches | grep "^$prefix" | sed "s,^$prefix,," | sort
68end
69
70function __fish_git_flow_remote_branches
71 set prefix (__fish_git_flow_prefix $argv[1])
72 set origin (git config gitflow.origin 2> /dev/null; or echo "origin")
73 git branch -r 2> /dev/null | sed "s/^ *//g" | grep "^$origin/$prefix" | sed "s,^$origin/$prefix,," | sort
74end
75
76function __fish_git_flow_untracked_branches
77 set branches (__fish_git_flow_branches $argv[1])
78 for branch in (__fish_git_flow_remote_branches $argv[1])
79 if not contains $branch $branches
80 echo $branch
81 end
82 end
83end
84
85function __fish_git_flow_unpublished_branches
86 set branches (__fish_git_flow_remote_branches $argv[1])
87 for branch in (__fish_git_flow_branches $argv[1])
88 if not contains $branch $branches
89 echo $branch
90 end
91 end
92end
93
94
95## git-flow
96
97complete -f -c git -n '__fish_git_needs_command' -a flow -d 'Manage a git-flow enabled repository'
98complete -f -c git -n '__fish_git_flow_using_command' -a version -d 'Show version information'
99
100
101
102## git-flow init
103
104complete -f -c git -n '__fish_git_flow_using_command' -a init -d 'Initialize a new git repo with support for the branching model'
105complete -f -c git -n '__fish_git_flow_using_command init' -s f -d 'Force reinitialization'
106complete -f -c git -n '__fish_git_flow_using_command init' -s d -d 'Use default branch names'
107
108
109
110## git-flow feature
111
112complete -f -c git -n '__fish_git_flow_using_command' -a feature -d 'Manage feature branches'
113complete -f -c git -n '__fish_git_flow_using_command feature' -a list -d 'List feature branches'
114complete -f -c git -n '__fish_git_flow_using_command feature' -s v -d 'Verbose output'
115
116complete -f -c git -n '__fish_git_flow_using_command feature' -a start -d 'Start a new feature branch'
117complete -f -c git -n '__fish_git_flow_using_command feature start' -s F -d 'Fetch from origin first'
118
119complete -f -c git -n '__fish_git_flow_using_command feature' -a finish -d 'Finish a feature branch'
120complete -f -c git -n '__fish_git_flow_using_command feature finish' -s F -d 'Fetch from origin first'
121complete -f -c git -n '__fish_git_flow_using_command feature finish' -s r -d 'Rebase instead of merging'
122complete -f -c git -n '__fish_git_flow_using_command feature finish' -a '(__fish_git_flow_branches feature)' -d 'Feature branch'
123
124complete -f -c git -n '__fish_git_flow_using_command feature' -a publish -d 'Publish a feature branch to remote'
125complete -f -c git -n '__fish_git_flow_using_command feature publish' -a '(__fish_git_flow_unpublished_branches feature)' -d 'Feature branch'
126
127complete -f -c git -n '__fish_git_flow_using_command feature' -a track -d 'Checkout remote feature branch'
128complete -f -c git -n '__fish_git_flow_using_command feature track' -a '(__fish_git_flow_untracked_branches feature)' -d 'Feature branch'
129
130complete -f -c git -n '__fish_git_flow_using_command feature' -a diff -d 'Show all changes'
131
132complete -f -c git -n '__fish_git_flow_using_command feature' -a rebase -d 'Rebase against integration branch'
133complete -f -c git -n '__fish_git_flow_using_command feature rebase' -s i -d 'Do an interactive rebase'
134
135complete -f -c git -n '__fish_git_flow_using_command feature' -a checkout -d 'Checkout local feature branch'
136complete -f -c git -n '__fish_git_flow_using_command feature checkout' -a '(__fish_git_flow_branches feature)' -d 'Feature branch'
137
138complete -f -c git -n '__fish_git_flow_using_command feature' -a pull -d 'Pull changes from remote'
139complete -f -c git -n '__fish_git_flow_using_command feature pull' -a '(__fish_git_remotes)' -d 'Remote'
140
141
142
143## git-flow release
144
145complete -f -c git -n '__fish_git_flow_using_command' -a release -d 'Manage release branches'
146complete -f -c git -n '__fish_git_flow_using_command release' -a list -d 'List release branches'
147complete -f -c git -n '__fish_git_flow_using_command release' -s v -d 'Verbose output'
148
149complete -f -c git -n '__fish_git_flow_using_command release' -a start -d 'Start a new release branch'
150complete -f -c git -n '__fish_git_flow_using_command release start' -s F -d 'Fetch from origin first'
151
152complete -f -c git -n '__fish_git_flow_using_command release' -a finish -d 'Finish a release branch'
153complete -f -c git -n '__fish_git_flow_using_command release finish' -s F -d 'Fetch from origin first'
154complete -f -c git -n '__fish_git_flow_using_command release finish' -s s -d 'Sign the release tag cryptographically'
155complete -f -c git -n '__fish_git_flow_using_command release finish' -s u -d 'Use the given GPG-key for the digital signature (implies -s)'
156complete -f -c git -n '__fish_git_flow_using_command release finish' -s m -d 'Use the given tag message'
157complete -f -c git -n '__fish_git_flow_using_command release finish' -s p -d 'Push to $ORIGIN after performing finish'
158complete -f -c git -n '__fish_git_flow_using_command release finish' -a '(__fish_git_flow_branches release)' -d 'Release branch'
159
160complete -f -c git -n '__fish_git_flow_using_command release' -a publish -d 'Publish a release branch to remote'
161complete -f -c git -n '__fish_git_flow_using_command release publish' -a '(__fish_git_flow_unpublished_branches release)' -d 'Release branch'
162
163complete -f -c git -n '__fish_git_flow_using_command release' -a track -d 'Checkout remote release branch'
164complete -f -c git -n '__fish_git_flow_using_command release track' -a '(__fish_git_flow_untracked_branches release)' -d 'Release branch'
165
166
167
168## git-flow hotfix
169
170complete -f -c git -n '__fish_git_flow_using_command' -a hotfix -d 'Manage hotfix branches'
171complete -f -c git -n '__fish_git_flow_using_command hotfix' -a list -d 'List hotfix branches'
172complete -f -c git -n '__fish_git_flow_using_command hotfix' -s v -d 'Verbose output'
173
174complete -f -c git -n '__fish_git_flow_using_command hotfix' -a start -d 'Start a new hotfix branch'
175complete -f -c git -n '__fish_git_flow_using_command hotfix start' -s F -d 'Fetch from origin first'
176
177complete -f -c git -n '__fish_git_flow_using_command hotfix' -a finish -d 'Finish a hotfix branch'
178complete -f -c git -n '__fish_git_flow_using_command hotfix finish' -s F -d 'Fetch from origin first'
179complete -f -c git -n '__fish_git_flow_using_command hotfix finish' -s s -d 'Sign the hotfix tag cryptographically'
180complete -f -c git -n '__fish_git_flow_using_command hotfix finish' -s u -d 'Use the given GPG-key for the digital signature (implies -s)'
181complete -f -c git -n '__fish_git_flow_using_command hotfix finish' -s m -d 'Use the given tag message'
182complete -f -c git -n '__fish_git_flow_using_command hotfix finish' -s p -d 'Push to $ORIGIN after performing finish'
183complete -f -c git -n '__fish_git_flow_using_command hotfix finish' -a '(__fish_git_flow_branches hotfix)' -d 'Hotfix branch'
184
185
186
187## git-flow support
188
189complete -f -c git -n '__fish_git_flow_using_command' -a support -d 'Manage support branches'
190complete -f -c git -n '__fish_git_flow_using_command support' -a list -d 'List support branches'
191complete -f -c git -n '__fish_git_flow_using_command support' -s v -d 'Verbose output'
192
193complete -f -c git -n '__fish_git_flow_using_command support' -a start -d 'Start a new support branch'
194complete -f -c git -n '__fish_git_flow_using_command support start' -s F -d 'Fetch from origin first'
195