git-flow.plugin.zsh 8.0 KB

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