git-flow-avh.plugin.zsh 9.0 KB

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