git-hubflow.plugin.zsh 10 KB

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