Justin Hileman | 2fdbd74 | 2012-07-24 11:51:26 -0700 | [diff] [blame] | 1 | #!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 Hileman | 80d3646 | 2012-07-24 11:56:33 -0700 | [diff] [blame] | 20 | # 1. Install this file in your `~/.config/fish/completions` folder. |
Justin Hileman | 2fdbd74 | 2012-07-24 11:51:26 -0700 | [diff] [blame] | 21 | # |
| 22 | # |
| 23 | # The Fine Print |
| 24 | # -------------- |
| 25 | # |
Justin Hileman | eb959a3 | 2014-03-13 22:57:18 -0700 | [diff] [blame] | 26 | # Copyright (c) 2012-2014 [Justin Hileman](http://justinhileman.com) |
Justin Hileman | 2fdbd74 | 2012-07-24 11:51:26 -0700 | [diff] [blame] | 27 | # |
| 28 | # Distributed under the [MIT License](http://creativecommons.org/licenses/MIT/) |
| 29 | |
| 30 | for 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 |
| 35 | end |
| 36 | |
| 37 | if not functions -q __fish_git_branches |
| 38 | echo \nError: git completion not found >&2 |
| 39 | exit |
| 40 | end |
| 41 | |
| 42 | ## Support functions |
| 43 | |
| 44 | function __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 |
| 56 | end |
| 57 | |
| 58 | function __fish_git_flow_prefix |
| 59 | git config "gitflow.prefix.$argv[1]" 2> /dev/null; or echo "$argv[1]/" |
| 60 | end |
| 61 | |
| 62 | function __fish_git_flow_branches |
| 63 | set prefix (__fish_git_flow_prefix $argv[1]) |
| 64 | __fish_git_branches | grep "^$prefix" | sed "s,^$prefix,," | sort |
| 65 | end |
| 66 | |
| 67 | function __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 |
| 71 | end |
| 72 | |
| 73 | function __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 |
| 80 | end |
| 81 | |
| 82 | function __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 |
| 89 | end |
| 90 | |
| 91 | |
| 92 | ## git-flow |
| 93 | |
| 94 | complete -f -c git -n '__fish_git_needs_command' -a flow -d 'Manage a git-flow enabled repository' |
| 95 | complete -f -c git -n '__fish_git_flow_using_command' -a version -d 'Show version information' |
| 96 | |
| 97 | |
| 98 | |
| 99 | ## git-flow init |
| 100 | |
| 101 | complete -f -c git -n '__fish_git_flow_using_command' -a init -d 'Initialize a new git repo with support for the branching model' |
| 102 | complete -f -c git -n '__fish_git_flow_using_command init' -s f -d 'Force reinitialization' |
| 103 | complete -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 | |
| 109 | complete -f -c git -n '__fish_git_flow_using_command' -a feature -d 'Manage feature branches' |
| 110 | complete -f -c git -n '__fish_git_flow_using_command feature' -a list -d 'List feature branches' |
| 111 | complete -f -c git -n '__fish_git_flow_using_command feature' -s v -d 'Verbose output' |
| 112 | |
| 113 | complete -f -c git -n '__fish_git_flow_using_command feature' -a start -d 'Start a new feature branch' |
| 114 | complete -f -c git -n '__fish_git_flow_using_command feature start' -s F -d 'Fetch from origin first' |
| 115 | |
| 116 | complete -f -c git -n '__fish_git_flow_using_command feature' -a finish -d 'Finish a feature branch' |
| 117 | complete -f -c git -n '__fish_git_flow_using_command feature finish' -s F -d 'Fetch from origin first' |
| 118 | complete -f -c git -n '__fish_git_flow_using_command feature finish' -s r -d 'Rebase instead of merging' |
| 119 | complete -f -c git -n '__fish_git_flow_using_command feature finish' -a '(__fish_git_flow_branches feature)' -d 'Feature branch' |
| 120 | |
| 121 | complete -f -c git -n '__fish_git_flow_using_command feature' -a publish -d 'Publish a feature branch to remote' |
| 122 | complete -f -c git -n '__fish_git_flow_using_command feature publish' -a '(__fish_git_flow_unpublished_branches feature)' -d 'Feature branch' |
| 123 | |
| 124 | complete -f -c git -n '__fish_git_flow_using_command feature' -a track -d 'Checkout remote feature branch' |
| 125 | complete -f -c git -n '__fish_git_flow_using_command feature track' -a '(__fish_git_flow_untracked_branches feature)' -d 'Feature branch' |
| 126 | |
| 127 | complete -f -c git -n '__fish_git_flow_using_command feature' -a diff -d 'Show all changes' |
| 128 | |
| 129 | complete -f -c git -n '__fish_git_flow_using_command feature' -a rebase -d 'Rebase against integration branch' |
| 130 | complete -f -c git -n '__fish_git_flow_using_command feature rebase' -s i -d 'Do an interactive rebase' |
| 131 | |
| 132 | complete -f -c git -n '__fish_git_flow_using_command feature' -a checkout -d 'Checkout local feature branch' |
| 133 | complete -f -c git -n '__fish_git_flow_using_command feature checkout' -a '(__fish_git_flow_branches feature)' -d 'Feature branch' |
| 134 | |
| 135 | complete -f -c git -n '__fish_git_flow_using_command feature' -a pull -d 'Pull changes from remote' |
| 136 | complete -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 | |
| 142 | complete -f -c git -n '__fish_git_flow_using_command' -a release -d 'Manage release branches' |
| 143 | complete -f -c git -n '__fish_git_flow_using_command release' -a list -d 'List release branches' |
| 144 | complete -f -c git -n '__fish_git_flow_using_command release' -s v -d 'Verbose output' |
| 145 | |
| 146 | complete -f -c git -n '__fish_git_flow_using_command release' -a start -d 'Start a new release branch' |
| 147 | complete -f -c git -n '__fish_git_flow_using_command release start' -s F -d 'Fetch from origin first' |
| 148 | |
| 149 | complete -f -c git -n '__fish_git_flow_using_command release' -a finish -d 'Finish a release branch' |
| 150 | complete -f -c git -n '__fish_git_flow_using_command release finish' -s F -d 'Fetch from origin first' |
| 151 | complete -f -c git -n '__fish_git_flow_using_command release finish' -s s -d 'Sign the release tag cryptographically' |
| 152 | complete -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)' |
| 153 | complete -f -c git -n '__fish_git_flow_using_command release finish' -s m -d 'Use the given tag message' |
| 154 | complete -f -c git -n '__fish_git_flow_using_command release finish' -s p -d 'Push to $ORIGIN after performing finish' |
| 155 | complete -f -c git -n '__fish_git_flow_using_command release finish' -a '(__fish_git_flow_branches release)' -d 'Release branch' |
| 156 | |
| 157 | complete -f -c git -n '__fish_git_flow_using_command release' -a publish -d 'Publish a release branch to remote' |
| 158 | complete -f -c git -n '__fish_git_flow_using_command release publish' -a '(__fish_git_flow_unpublished_branches release)' -d 'Release branch' |
| 159 | |
| 160 | complete -f -c git -n '__fish_git_flow_using_command release' -a track -d 'Checkout remote release branch' |
| 161 | complete -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 | |
| 167 | complete -f -c git -n '__fish_git_flow_using_command' -a hotfix -d 'Manage hotfix branches' |
| 168 | complete -f -c git -n '__fish_git_flow_using_command hotfix' -a list -d 'List hotfix branches' |
| 169 | complete -f -c git -n '__fish_git_flow_using_command hotfix' -s v -d 'Verbose output' |
| 170 | |
| 171 | complete -f -c git -n '__fish_git_flow_using_command hotfix' -a start -d 'Start a new hotfix branch' |
| 172 | complete -f -c git -n '__fish_git_flow_using_command hotfix start' -s F -d 'Fetch from origin first' |
| 173 | |
| 174 | complete -f -c git -n '__fish_git_flow_using_command hotfix' -a finish -d 'Finish a hotfix branch' |
| 175 | complete -f -c git -n '__fish_git_flow_using_command hotfix finish' -s F -d 'Fetch from origin first' |
| 176 | complete -f -c git -n '__fish_git_flow_using_command hotfix finish' -s s -d 'Sign the hotfix tag cryptographically' |
| 177 | complete -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)' |
| 178 | complete -f -c git -n '__fish_git_flow_using_command hotfix finish' -s m -d 'Use the given tag message' |
| 179 | complete -f -c git -n '__fish_git_flow_using_command hotfix finish' -s p -d 'Push to $ORIGIN after performing finish' |
| 180 | complete -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 | |
| 186 | complete -f -c git -n '__fish_git_flow_using_command' -a support -d 'Manage support branches' |
| 187 | complete -f -c git -n '__fish_git_flow_using_command support' -a list -d 'List support branches' |
| 188 | complete -f -c git -n '__fish_git_flow_using_command support' -s v -d 'Verbose output' |
| 189 | |
| 190 | complete -f -c git -n '__fish_git_flow_using_command support' -a start -d 'Start a new support branch' |
| 191 | complete -f -c git -n '__fish_git_flow_using_command support start' -s F -d 'Fetch from origin first' |
| 192 | |