git-flow.plugin.zsh 8.4 KB

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