git-flow-avh.plugin.zsh 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548
  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://github.com/zsh-users/zsh/blob/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 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. 'bugfix:Manage your bugfix branches.'
  36. 'config:Manage your configuration.'
  37. 'release:Manage your release branches.'
  38. 'hotfix:Manage your hotfix branches.'
  39. 'support:Manage your support branches.'
  40. 'version:Shows version information.'
  41. 'finish:Finish the branch you are currently on.'
  42. 'delete:Delete the branch you are currently on.'
  43. 'publish:Publish the branch you are currently on.'
  44. 'rebase:Rebase the branch you are currently on.'
  45. )
  46. _describe -t commands 'git flow' subcommands
  47. ;;
  48. (options)
  49. case $line[1] in
  50. (init)
  51. _arguments \
  52. -f'[Force setting of gitflow branches, even if already configured]'
  53. ;;
  54. (version)
  55. ;;
  56. (hotfix)
  57. __git-flow-hotfix
  58. ;;
  59. (release)
  60. __git-flow-release
  61. ;;
  62. (feature)
  63. __git-flow-feature
  64. ;;
  65. (bugfix)
  66. __git-flow-bugfix
  67. ;;
  68. (config)
  69. __git-flow-config
  70. ;;
  71. esac
  72. ;;
  73. esac
  74. }
  75. __git-flow-release ()
  76. {
  77. local curcontext="$curcontext" state line
  78. typeset -A opt_args
  79. _arguments -C \
  80. ':command:->command' \
  81. '*::options:->options'
  82. case $state in
  83. (command)
  84. local -a subcommands
  85. subcommands=(
  86. 'start:Start a new release branch.'
  87. 'finish:Finish a release branch.'
  88. 'list:List all your release branches. (Alias to `git flow release`)'
  89. 'publish:Publish release branch to remote.'
  90. 'track:Checkout remote release branch.'
  91. 'rebase:Rebase from integration branch.'
  92. 'delete:Delete a release branch.'
  93. )
  94. _describe -t commands 'git flow release' subcommands
  95. _arguments \
  96. -v'[Verbose (more) output]'
  97. ;;
  98. (options)
  99. case $line[1] in
  100. (start)
  101. _arguments \
  102. -F'[Fetch from origin before performing finish]'\
  103. ':version:__git_flow_version_list'
  104. ;;
  105. (finish)
  106. _arguments \
  107. -F'[Fetch from origin before performing finish]' \
  108. -s'[Sign the release tag cryptographically]'\
  109. -u'[Use the given GPG-key for the digital signature (implies -s)]'\
  110. -m'[Use the given tag message]'\
  111. -p'[Push to $ORIGIN after performing finish]'\
  112. ':version:__git_flow_version_list'
  113. ;;
  114. (delete)
  115. _arguments \
  116. -f'[Force deletion]' \
  117. -r'[Delete remote branch]' \
  118. ':version:__git_flow_version_list'
  119. ;;
  120. (publish)
  121. _arguments \
  122. ':version:__git_flow_version_list'
  123. ;;
  124. (track)
  125. _arguments \
  126. ':version:__git_flow_version_list'
  127. ;;
  128. (rebase)
  129. _arguments \
  130. -i'[Do an interactive rebase]' \
  131. ':branch:__git_branch_names'
  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. 'delete:Delete a hotfix branch.'
  155. 'rebase:Rebase from integration branch.'
  156. 'list:List all your hotfix branches. (Alias to `git flow hotfix`)'
  157. 'rename:Rename a hotfix branch.'
  158. )
  159. _describe -t commands 'git flow hotfix' subcommands
  160. _arguments \
  161. -v'[Verbose (more) output]'
  162. ;;
  163. (options)
  164. case $line[1] in
  165. (start)
  166. _arguments \
  167. -F'[Fetch from origin before performing finish]'\
  168. ':hotfix:__git_flow_version_list'\
  169. ':branch-name:__git_branch_names'
  170. ;;
  171. (finish)
  172. _arguments \
  173. -F'[Fetch from origin before performing finish]' \
  174. -s'[Sign the release tag cryptographically]'\
  175. -u'[Use the given GPG-key for the digital signature (implies -s)]'\
  176. -m'[Use the given tag message]'\
  177. -p'[Push to $ORIGIN after performing finish]'\
  178. ':hotfix:__git_flow_hotfix_list'
  179. ;;
  180. (delete)
  181. _arguments \
  182. -f'[Force deletion]' \
  183. -r'[Delete remote branch]' \
  184. ':hotfix:__git_flow_hotfix_list'
  185. ;;
  186. (rebase)
  187. _arguments \
  188. -i'[Do an interactive rebase]' \
  189. ':branch:__git_branch_names'
  190. ;;
  191. *)
  192. _arguments \
  193. -v'[Verbose (more) output]'
  194. ;;
  195. esac
  196. ;;
  197. esac
  198. }
  199. __git-flow-feature ()
  200. {
  201. local curcontext="$curcontext" state line
  202. typeset -A opt_args
  203. _arguments -C \
  204. ':command:->command' \
  205. '*::options:->options'
  206. case $state in
  207. (command)
  208. local -a subcommands
  209. subcommands=(
  210. 'start:Start a new feature branch.'
  211. 'finish:Finish a feature branch.'
  212. 'delete:Delete a feature branch.'
  213. 'list:List all your feature branches. (Alias to `git flow feature`)'
  214. 'publish:Publish feature branch to remote.'
  215. 'track:Checkout remote feature branch.'
  216. 'diff:Show all changes.'
  217. 'rebase:Rebase from integration branch.'
  218. 'checkout:Checkout local feature branch.'
  219. 'pull:Pull changes from remote.'
  220. 'rename:Rename a feature branch.'
  221. )
  222. _describe -t commands 'git flow feature' subcommands
  223. _arguments \
  224. -v'[Verbose (more) output]'
  225. ;;
  226. (options)
  227. case $line[1] in
  228. (start)
  229. _arguments \
  230. -F'[Fetch from origin before performing finish]'\
  231. ':feature:__git_flow_feature_list'\
  232. ':branch-name:__git_branch_names'
  233. ;;
  234. (finish)
  235. _arguments \
  236. -F'[Fetch from origin before performing finish]' \
  237. -r'[Rebase instead of merge]'\
  238. ':feature:__git_flow_feature_list'
  239. ;;
  240. (delete)
  241. _arguments \
  242. -f'[Force deletion]' \
  243. -r'[Delete remote branch]' \
  244. ':feature:__git_flow_feature_list'
  245. ;;
  246. (publish)
  247. _arguments \
  248. ':feature:__git_flow_feature_list'\
  249. ;;
  250. (track)
  251. _arguments \
  252. ':feature:__git_flow_feature_list'\
  253. ;;
  254. (diff)
  255. _arguments \
  256. ':branch:__git_branch_names'\
  257. ;;
  258. (rebase)
  259. _arguments \
  260. -i'[Do an interactive rebase]' \
  261. ':branch:__git_branch_names'
  262. ;;
  263. (checkout)
  264. _arguments \
  265. ':branch:__git_flow_feature_list'\
  266. ;;
  267. (pull)
  268. _arguments \
  269. ':remote:__git_remotes'\
  270. ':branch:__git_branch_names'
  271. ;;
  272. *)
  273. _arguments \
  274. -v'[Verbose (more) output]'
  275. ;;
  276. esac
  277. ;;
  278. esac
  279. }
  280. __git-flow-bugfix ()
  281. {
  282. local curcontext="$curcontext" state line
  283. typeset -A opt_args
  284. _arguments -C \
  285. ':command:->command' \
  286. '*::options:->options'
  287. case $state in
  288. (command)
  289. local -a subcommands
  290. subcommands=(
  291. 'start:Start a new bugfix branch.'
  292. 'finish:Finish a bugfix branch.'
  293. 'delete:Delete a bugfix branch.'
  294. 'list:List all your bugfix branches. (Alias to `git flow bugfix`)'
  295. 'publish:Publish bugfix branch to remote.'
  296. 'track:Checkout remote bugfix branch.'
  297. 'diff:Show all changes.'
  298. 'rebase:Rebase from integration branch.'
  299. 'checkout:Checkout local bugfix branch.'
  300. 'pull:Pull changes from remote.'
  301. 'rename:Rename a bugfix branch.'
  302. )
  303. _describe -t commands 'git flow bugfix' subcommands
  304. _arguments \
  305. -v'[Verbose (more) output]'
  306. ;;
  307. (options)
  308. case $line[1] in
  309. (start)
  310. _arguments \
  311. -F'[Fetch from origin before performing finish]'\
  312. ':bugfix:__git_flow_bugfix_list'\
  313. ':branch-name:__git_branch_names'
  314. ;;
  315. (finish)
  316. _arguments \
  317. -F'[Fetch from origin before performing finish]' \
  318. -r'[Rebase instead of merge]'\
  319. ':bugfix:__git_flow_bugfix_list'
  320. ;;
  321. (delete)
  322. _arguments \
  323. -f'[Force deletion]' \
  324. -r'[Delete remote branch]' \
  325. ':bugfix:__git_flow_bugfix_list'
  326. ;;
  327. (publish)
  328. _arguments \
  329. ':bugfix:__git_flow_bugfix_list'\
  330. ;;
  331. (track)
  332. _arguments \
  333. ':bugfix:__git_flow_bugfix_list'\
  334. ;;
  335. (diff)
  336. _arguments \
  337. ':branch:__git_branch_names'\
  338. ;;
  339. (rebase)
  340. _arguments \
  341. -i'[Do an interactive rebase]' \
  342. ':branch:__git_branch_names'
  343. ;;
  344. (checkout)
  345. _arguments \
  346. ':branch:__git_flow_bugfix_list'\
  347. ;;
  348. (pull)
  349. _arguments \
  350. ':remote:__git_remotes'\
  351. ':branch:__git_branch_names'
  352. ;;
  353. *)
  354. _arguments \
  355. -v'[Verbose (more) output]'
  356. ;;
  357. esac
  358. ;;
  359. esac
  360. }
  361. __git-flow-config ()
  362. {
  363. local curcontext="$curcontext" state line
  364. typeset -A opt_args
  365. _arguments -C \
  366. ':command:->command' \
  367. '*::options:->options'
  368. case $state in
  369. (command)
  370. local -a subcommands
  371. subcommands=(
  372. 'list:List the configuration. (Alias to `git flow config`)'
  373. 'set:Set the configuration option'
  374. )
  375. _describe -t commands 'git flow config' subcommands
  376. ;;
  377. (options)
  378. case $line[1] in
  379. (set)
  380. _arguments \
  381. --local'[Use repository config file]' \
  382. --global'[Use global config file]'\
  383. --system'[Use system config file]'\
  384. --file'[Use given config file]'\
  385. ':option:(master develop feature hotfix release support versiontagprefix)'
  386. ;;
  387. *)
  388. _arguments \
  389. --local'[Use repository config file]' \
  390. --global'[Use global config file]'\
  391. --system'[Use system config file]'\
  392. --file'[Use given config file]'
  393. ;;
  394. esac
  395. ;;
  396. esac
  397. }
  398. __git_flow_version_list ()
  399. {
  400. local expl
  401. declare -a versions
  402. versions=(${${(f)"$(_call_program versions git flow release list 2> /dev/null | tr -d ' |*')"}})
  403. __git_command_successful || return
  404. _wanted versions expl 'version' compadd $versions
  405. }
  406. __git_flow_feature_list ()
  407. {
  408. local expl
  409. declare -a features
  410. features=(${${(f)"$(_call_program features git flow feature list 2> /dev/null | tr -d ' |*')"}})
  411. __git_command_successful || return
  412. _wanted features expl 'feature' compadd $features
  413. }
  414. __git_flow_bugfix_list ()
  415. {
  416. local expl
  417. declare -a bugfixes
  418. bugfixes=(${${(f)"$(_call_program bugfixes git flow bugfix list 2> /dev/null | tr -d ' |*')"}})
  419. __git_command_successful || return
  420. _wanted bugfixes expl 'bugfix' compadd $bugfixes
  421. }
  422. __git_remotes () {
  423. local expl gitdir remotes
  424. gitdir=$(_call_program gitdir git rev-parse --git-dir 2>/dev/null)
  425. __git_command_successful || return
  426. remotes=(${${(f)"$(_call_program remotes git config --get-regexp '"^remote\..*\.url$"')"}//#(#b)remote.(*).url */$match[1]})
  427. __git_command_successful || return
  428. # TODO: Should combine the two instead of either or.
  429. if (( $#remotes > 0 )); then
  430. _wanted remotes expl remote compadd $* - $remotes
  431. else
  432. _wanted remotes expl remote _files $* - -W "($gitdir/remotes)" -g "$gitdir/remotes/*"
  433. fi
  434. }
  435. __git_flow_hotfix_list ()
  436. {
  437. local expl
  438. declare -a hotfixes
  439. hotfixes=(${${(f)"$(_call_program hotfixes git flow hotfix list 2> /dev/null | tr -d ' |*')"}})
  440. __git_command_successful || return
  441. _wanted hotfixes expl 'hotfix' compadd $hotfixes
  442. }
  443. __git_branch_names () {
  444. local expl
  445. declare -a branch_names
  446. branch_names=(${${(f)"$(_call_program branchrefs git for-each-ref --format='"%(refname)"' refs/heads 2>/dev/null)"}#refs/heads/})
  447. __git_command_successful || return
  448. _wanted branch-names expl branch-name compadd $* - $branch_names
  449. }
  450. __git_command_successful () {
  451. if (( ${#pipestatus:#0} > 0 )); then
  452. _message 'not a git repository'
  453. return 1
  454. fi
  455. return 0
  456. }
  457. zstyle ':completion:*:*:git:*' user-commands flow:'provide high-level repository operations'