git-hubflow.plugin.zsh 9.6 KB

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