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