git-flow.plugin.zsh 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. #!zsh
  2. #
  3. # Installation
  4. # ------------
  5. #
  6. # To achieve git-flow completion nirvana:
  7. #
  8. # 0. Update your zsh's git-completion module to the newest verion.
  9. # From here. http://zsh.git.sourceforge.net/git/gitweb.cgi?p=zsh/zsh;a=blob_plain;f=Completion/Unix/Command/_git;hb=HEAD
  10. #
  11. # 1. Install this file. Either:
  12. #
  13. # a. Place it in your .zshrc:
  14. #
  15. # b. Or, copy it somewhere (e.g. ~/.git-flow-completion.zsh) and put the following line in
  16. # your .zshrc:
  17. #
  18. # source ~/.git-flow-completion.zsh
  19. #
  20. # c. Or, use this file as a oh-my-zsh plugin.
  21. #
  22. _git-flow ()
  23. {
  24. local curcontext="$curcontext" state line
  25. typeset -A opt_args
  26. _arguments -C \
  27. ':command:->command' \
  28. '*::options:->options'
  29. case $state in
  30. (command)
  31. local -a subcommands
  32. subcommands=(
  33. 'init:Initialize a new git repo with support for the branching model.'
  34. 'feature:Manage your feature branches.'
  35. 'release:Manage your release branches.'
  36. 'hotfix:Manage your hotfix branches.'
  37. 'support:Manage your support branches.'
  38. 'version:Shows version information.'
  39. )
  40. _describe -t commands 'git flow' subcommands
  41. ;;
  42. (options)
  43. case $line[1] in
  44. (init)
  45. _arguments \
  46. -f'[Force setting of gitflow branches, even if already configured]'
  47. ;;
  48. (version)
  49. ;;
  50. (hotfix)
  51. __git-flow-hotfix
  52. ;;
  53. (release)
  54. __git-flow-release
  55. ;;
  56. (feature)
  57. __git-flow-feature
  58. ;;
  59. esac
  60. ;;
  61. esac
  62. }
  63. __git-flow-release ()
  64. {
  65. local curcontext="$curcontext" state line
  66. typeset -A opt_args
  67. _arguments -C \
  68. ':command:->command' \
  69. '*::options:->options'
  70. case $state in
  71. (command)
  72. local -a subcommands
  73. subcommands=(
  74. 'start:Start a new release branch.'
  75. 'finish:Finish a release branch.'
  76. 'list:List all your release branches. (Alias to `git flow release`)'
  77. )
  78. _describe -t commands 'git flow release' subcommands
  79. _arguments \
  80. -v'[Verbose (more) output]'
  81. ;;
  82. (options)
  83. case $line[1] in
  84. (start)
  85. _arguments \
  86. -F'[Fetch from origin before performing finish]'\
  87. ':version:__git_flow_version_list'
  88. ;;
  89. (finish)
  90. _arguments \
  91. -F'[Fetch from origin before performing finish]' \
  92. -s'[Sign the release tag cryptographically]'\
  93. -u'[Use the given GPG-key for the digital signature (implies -s)]'\
  94. -m'[Use the given tag message]'\
  95. -p'[Push to $ORIGIN after performing finish]'\
  96. -k'[Keep branch after performing finish]'\
  97. -n"[Don't tag this release]"\
  98. ':version:__git_flow_version_list'
  99. ;;
  100. *)
  101. _arguments \
  102. -v'[Verbose (more) output]'
  103. ;;
  104. esac
  105. ;;
  106. esac
  107. }
  108. __git-flow-hotfix ()
  109. {
  110. local curcontext="$curcontext" state line
  111. typeset -A opt_args
  112. _arguments -C \
  113. ':command:->command' \
  114. '*::options:->options'
  115. case $state in
  116. (command)
  117. local -a subcommands
  118. subcommands=(
  119. 'start:Start a new hotfix branch.'
  120. 'finish:Finish a hotfix branch.'
  121. 'list:List all your hotfix branches. (Alias to `git flow hotfix`)'
  122. )
  123. _describe -t commands 'git flow hotfix' subcommands
  124. _arguments \
  125. -v'[Verbose (more) output]'
  126. ;;
  127. (options)
  128. case $line[1] in
  129. (start)
  130. _arguments \
  131. -F'[Fetch from origin before performing finish]'\
  132. ':hotfix:__git_flow_version_list'\
  133. ':branch-name:__git_branch_names'
  134. ;;
  135. (finish)
  136. _arguments \
  137. -F'[Fetch from origin before performing finish]' \
  138. -s'[Sign the release tag cryptographically]'\
  139. -u'[Use the given GPG-key for the digital signature (implies -s)]'\
  140. -m'[Use the given tag message]'\
  141. -p'[Push to $ORIGIN after performing finish]'\
  142. -k'[Keep branch after performing finish]'\
  143. -n"[Don't tag this release]"\
  144. ':hotfix:__git_flow_hotfix_list'
  145. ;;
  146. *)
  147. _arguments \
  148. -v'[Verbose (more) output]'
  149. ;;
  150. esac
  151. ;;
  152. esac
  153. }
  154. __git-flow-feature ()
  155. {
  156. local curcontext="$curcontext" state line
  157. typeset -A opt_args
  158. _arguments -C \
  159. ':command:->command' \
  160. '*::options:->options'
  161. case $state in
  162. (command)
  163. local -a subcommands
  164. subcommands=(
  165. 'start:Start a new feature branch.'
  166. 'finish:Finish a feature branch.'
  167. 'list:List all your feature branches. (Alias to `git flow feature`)'
  168. 'publish: publish'
  169. 'track: track'
  170. 'diff: diff'
  171. 'rebase: rebase'
  172. 'checkout: checkout'
  173. 'pull: pull'
  174. )
  175. _describe -t commands 'git flow feature' subcommands
  176. _arguments \
  177. -v'[Verbose (more) output]'
  178. ;;
  179. (options)
  180. case $line[1] in
  181. (start)
  182. _arguments \
  183. -F'[Fetch from origin before performing finish]'\
  184. ':feature:__git_flow_feature_list'\
  185. ':branch-name:__git_branch_names'
  186. ;;
  187. (finish)
  188. _arguments \
  189. -F'[Fetch from origin before performing finish]' \
  190. -r'[Rebase instead of merge]'\
  191. -k'[Keep branch after performing finish]'\
  192. ':feature:__git_flow_feature_list'
  193. ;;
  194. (publish)
  195. _arguments \
  196. ':feature:__git_flow_feature_list'\
  197. ;;
  198. (track)
  199. _arguments \
  200. ':feature:__git_flow_feature_list'\
  201. ;;
  202. (diff)
  203. _arguments \
  204. ':branch:__git_flow_feature_list'\
  205. ;;
  206. (rebase)
  207. _arguments \
  208. -i'[Do an interactive rebase]' \
  209. ':branch:__git_flow_feature_list'
  210. ;;
  211. (checkout)
  212. _arguments \
  213. ':branch:__git_flow_feature_list'\
  214. ;;
  215. (pull)
  216. _arguments \
  217. ':remote:__git_remotes'\
  218. ':branch:__git_flow_feature_list'
  219. ;;
  220. *)
  221. _arguments \
  222. -v'[Verbose (more) output]'
  223. ;;
  224. esac
  225. ;;
  226. esac
  227. }
  228. __git_flow_version_list ()
  229. {
  230. local expl
  231. declare -a versions
  232. versions=(${${(f)"$(_call_program versions git flow release list 2> /dev/null | tr -d ' |*')"}})
  233. __git_command_successful || return
  234. _wanted versions expl 'version' compadd $versions
  235. }
  236. __git_flow_feature_list ()
  237. {
  238. local expl
  239. declare -a features
  240. features=(${${(f)"$(_call_program features git flow feature list 2> /dev/null | tr -d ' |*')"}})
  241. __git_command_successful || return
  242. _wanted features expl 'feature' compadd $features
  243. }
  244. __git_remotes () {
  245. local expl gitdir remotes
  246. gitdir=$(_call_program gitdir git rev-parse --git-dir 2>/dev/null)
  247. __git_command_successful || return
  248. remotes=(${${(f)"$(_call_program remotes git config --get-regexp '"^remote\..*\.url$"')"}//#(#b)remote.(*).url */$match[1]})
  249. __git_command_successful || return
  250. # TODO: Should combine the two instead of either or.
  251. if (( $#remotes > 0 )); then
  252. _wanted remotes expl remote compadd $* - $remotes
  253. else
  254. _wanted remotes expl remote _files $* - -W "($gitdir/remotes)" -g "$gitdir/remotes/*"
  255. fi
  256. }
  257. __git_flow_hotfix_list ()
  258. {
  259. local expl
  260. declare -a hotfixes
  261. hotfixes=(${${(f)"$(_call_program hotfixes git flow hotfix list 2> /dev/null | tr -d ' |*')"}})
  262. __git_command_successful || return
  263. _wanted hotfixes expl 'hotfix' compadd $hotfixes
  264. }
  265. __git_branch_names () {
  266. local expl
  267. declare -a branch_names
  268. branch_names=(${${(f)"$(_call_program branchrefs git for-each-ref --format='"%(refname)"' refs/heads 2>/dev/null)"}#refs/heads/})
  269. __git_command_successful || return
  270. _wanted branch-names expl branch-name compadd $* - $branch_names
  271. }
  272. __git_command_successful () {
  273. if (( ${#pipestatus:#0} > 0 )); then
  274. _message 'not a git repository'
  275. return 1
  276. fi
  277. return 0
  278. }
  279. zstyle ':completion:*:*:git:*' user-commands flow:'description for foo'