git-flow.plugin.zsh 8.0 KB

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