git-flow.plugin.zsh 7.4 KB

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