git-flow-avh.plugin.zsh 8.9 KB

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