git-flow.plugin.zsh 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  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. ':version:__git_flow_version_list'
  97. ;;
  98. *)
  99. _arguments \
  100. -v'[Verbose (more) output]'
  101. ;;
  102. esac
  103. ;;
  104. esac
  105. }
  106. __git-flow-hotfix ()
  107. {
  108. local curcontext="$curcontext" state line
  109. typeset -A opt_args
  110. _arguments -C \
  111. ':command:->command' \
  112. '*::options:->options'
  113. case $state in
  114. (command)
  115. local -a subcommands
  116. subcommands=(
  117. 'start:Start a new hotfix branch.'
  118. 'finish:Finish a hotfix branch.'
  119. 'list:List all your hotfix branches. (Alias to `git flow hotfix`)'
  120. )
  121. _describe -t commands 'git flow hotfix' subcommands
  122. _arguments \
  123. -v'[Verbose (more) output]'
  124. ;;
  125. (options)
  126. case $line[1] in
  127. (start)
  128. _arguments \
  129. -F'[Fetch from origin before performing finish]'\
  130. ':hotfix:__git_flow_version_list'\
  131. ':branch-name:__git_branch_names'
  132. ;;
  133. (finish)
  134. _arguments \
  135. -F'[Fetch from origin before performing finish]' \
  136. -s'[Sign the release tag cryptographically]'\
  137. -u'[Use the given GPG-key for the digital signature (implies -s)]'\
  138. -m'[Use the given tag message]'\
  139. -p'[Push to $ORIGIN after performing finish]'\
  140. ':hotfix:__git_flow_hotfix_list'
  141. ;;
  142. *)
  143. _arguments \
  144. -v'[Verbose (more) output]'
  145. ;;
  146. esac
  147. ;;
  148. esac
  149. }
  150. __git-flow-feature ()
  151. {
  152. local curcontext="$curcontext" state line
  153. typeset -A opt_args
  154. _arguments -C \
  155. ':command:->command' \
  156. '*::options:->options'
  157. case $state in
  158. (command)
  159. local -a subcommands
  160. subcommands=(
  161. 'start:Start a new feature branch.'
  162. 'finish:Finish a feature branch.'
  163. 'list:List all your feature branches. (Alias to `git flow feature`)'
  164. 'publish: public'
  165. 'track: track'
  166. 'diff: diff'
  167. 'rebase: rebase'
  168. 'checkout: checkout'
  169. 'pull: pull'
  170. )
  171. _describe -t commands 'git flow feature' subcommands
  172. _arguments \
  173. -v'[Verbose (more) output]'
  174. ;;
  175. (options)
  176. case $line[1] in
  177. (start)
  178. _arguments \
  179. -F'[Fetch from origin before performing finish]'\
  180. ':feature:__git_flow_feature_list'\
  181. ':branch-name:__git_branch_names'
  182. ;;
  183. (finish)
  184. _arguments \
  185. -F'[Fetch from origin before performing finish]' \
  186. -r'[Rebase instead of merge]'\
  187. ':feature:__git_flow_feature_list'
  188. ;;
  189. (publish)
  190. _arguments \
  191. ':feature:__git_flow_feature_list'\
  192. ;;
  193. (track)
  194. _arguments \
  195. ':feature:__git_flow_feature_list'\
  196. ;;
  197. (diff)
  198. _arguments \
  199. ':branch:__git_branch_names'\
  200. ;;
  201. (rebase)
  202. _arguments \
  203. -i'[Do an interactive rebase]' \
  204. ':branch:__git_branch_names'
  205. ;;
  206. (checkout)
  207. _arguments \
  208. ':branch:__git_flow_feature_list'\
  209. ;;
  210. (pull)
  211. _arguments \
  212. ':remote:__git_remotes'\
  213. ':branch:__git_branch_names'
  214. ;;
  215. *)
  216. _arguments \
  217. -v'[Verbose (more) output]'
  218. ;;
  219. esac
  220. ;;
  221. esac
  222. }
  223. __git_flow_version_list ()
  224. {
  225. local expl
  226. declare -a versions
  227. versions=(${${(f)"$(_call_program versions git flow release list 2> /dev/null | tr -d ' |*')"}})
  228. __git_command_successful || return
  229. _wanted versions expl 'version' compadd $versions
  230. }
  231. __git_flow_feature_list ()
  232. {
  233. local expl
  234. declare -a features
  235. features=(${${(f)"$(_call_program features git flow feature list 2> /dev/null | tr -d ' |*')"}})
  236. __git_command_successful || return
  237. _wanted features expl 'feature' compadd $features
  238. }
  239. __git_remotes () {
  240. local expl gitdir remotes
  241. gitdir=$(_call_program gitdir git rev-parse --git-dir 2>/dev/null)
  242. __git_command_successful || return
  243. remotes=(${${(f)"$(_call_program remotes git config --get-regexp '"^remote\..*\.url$"')"}//#(#b)remote.(*).url */$match[1]})
  244. __git_command_successful || return
  245. # TODO: Should combine the two instead of either or.
  246. if (( $#remotes > 0 )); then
  247. _wanted remotes expl remote compadd $* - $remotes
  248. else
  249. _wanted remotes expl remote _files $* - -W "($gitdir/remotes)" -g "$gitdir/remotes/*"
  250. fi
  251. }
  252. __git_flow_hotfix_list ()
  253. {
  254. local expl
  255. declare -a hotfixes
  256. hotfixes=(${${(f)"$(_call_program hotfixes git flow hotfix list 2> /dev/null | tr -d ' |*')"}})
  257. __git_command_successful || return
  258. _wanted hotfixes expl 'hotfix' compadd $hotfixes
  259. }
  260. __git_branch_names () {
  261. local expl
  262. declare -a branch_names
  263. branch_names=(${${(f)"$(_call_program branchrefs git for-each-ref --format='"%(refname)"' refs/heads 2>/dev/null)"}#refs/heads/})
  264. __git_command_successful || return
  265. _wanted branch-names expl branch-name compadd $* - $branch_names
  266. }
  267. __git_command_successful () {
  268. if (( ${#pipestatus:#0} > 0 )); then
  269. _message 'not a git repository'
  270. return 1
  271. fi
  272. return 0
  273. }
  274. zstyle ':completion:*:*:git:*' user-commands flow:'description for foo'