git-flow.plugin.zsh 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  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: public'
  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. ':feature:__git_flow_feature_list'
  192. ;;
  193. (publish)
  194. _arguments \
  195. ':feature:__git_flow_feature_list'\
  196. ;;
  197. (track)
  198. _arguments \
  199. ':feature:__git_flow_feature_list'\
  200. ;;
  201. (diff)
  202. _arguments \
  203. ':branch:__git_branch_names'\
  204. ;;
  205. (rebase)
  206. _arguments \
  207. -i'[Do an interactive rebase]' \
  208. ':branch:__git_branch_names'
  209. ;;
  210. (checkout)
  211. _arguments \
  212. ':branch:__git_flow_feature_list'\
  213. ;;
  214. (pull)
  215. _arguments \
  216. ':remote:__git_remotes'\
  217. ':branch:__git_branch_names'
  218. ;;
  219. *)
  220. _arguments \
  221. -v'[Verbose (more) output]'
  222. ;;
  223. esac
  224. ;;
  225. esac
  226. }
  227. __git_flow_version_list ()
  228. {
  229. local expl
  230. declare -a versions
  231. versions=(${${(f)"$(_call_program versions git flow release list 2> /dev/null | tr -d ' |*')"}})
  232. __git_command_successful || return
  233. _wanted versions expl 'version' compadd $versions
  234. }
  235. __git_flow_feature_list ()
  236. {
  237. local expl
  238. declare -a features
  239. features=(${${(f)"$(_call_program features git flow feature list 2> /dev/null | tr -d ' |*')"}})
  240. __git_command_successful || return
  241. _wanted features expl 'feature' compadd $features
  242. }
  243. __git_remotes () {
  244. local expl gitdir remotes
  245. gitdir=$(_call_program gitdir git rev-parse --git-dir 2>/dev/null)
  246. __git_command_successful || return
  247. remotes=(${${(f)"$(_call_program remotes git config --get-regexp '"^remote\..*\.url$"')"}//#(#b)remote.(*).url */$match[1]})
  248. __git_command_successful || return
  249. # TODO: Should combine the two instead of either or.
  250. if (( $#remotes > 0 )); then
  251. _wanted remotes expl remote compadd $* - $remotes
  252. else
  253. _wanted remotes expl remote _files $* - -W "($gitdir/remotes)" -g "$gitdir/remotes/*"
  254. fi
  255. }
  256. __git_flow_hotfix_list ()
  257. {
  258. local expl
  259. declare -a hotfixes
  260. hotfixes=(${${(f)"$(_call_program hotfixes git flow hotfix list 2> /dev/null | tr -d ' |*')"}})
  261. __git_command_successful || return
  262. _wanted hotfixes expl 'hotfix' compadd $hotfixes
  263. }
  264. __git_branch_names () {
  265. local expl
  266. declare -a branch_names
  267. branch_names=(${${(f)"$(_call_program branchrefs git for-each-ref --format='"%(refname)"' refs/heads 2>/dev/null)"}#refs/heads/})
  268. __git_command_successful || return
  269. _wanted branch-names expl branch-name compadd $* - $branch_names
  270. }
  271. __git_command_successful () {
  272. if (( ${#pipestatus:#0} > 0 )); then
  273. _message 'not a git repository'
  274. return 1
  275. fi
  276. return 0
  277. }
  278. zstyle ':completion:*:*:git:*' user-commands flow:'description for foo'