git-hubflow.plugin.zsh 10.0 KB

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