_git-branch 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #compdef git-branch
  2. _git-branch ()
  3. {
  4. declare l c m d
  5. l='--color --no-color -r -a --all -v --verbose --abbrev --no-abbrev'
  6. c='-l -f --force -t --track --no-track --set-upstream --contains --merged --no-merged'
  7. m='-m -M'
  8. d='-d -D'
  9. declare -a dependent_creation_args
  10. if (( words[(I)-r] == 0 )); then
  11. dependent_creation_args=(
  12. "($l $m $d): :__git_branch_names"
  13. "::start-point:__git_revisions")
  14. fi
  15. declare -a dependent_deletion_args
  16. if (( words[(I)-d] || words[(I)-D] )); then
  17. dependent_creation_args=
  18. dependent_deletion_args=(
  19. '-r[delete only remote-tracking branches]')
  20. if (( words[(I)-r] )); then
  21. dependent_deletion_args+='*: :__git_ignore_line_inside_arguments __git_remote_branch_names'
  22. else
  23. dependent_deletion_args+='*: :__git_ignore_line_inside_arguments __git_branch_names'
  24. fi
  25. fi
  26. declare -a dependent_modification_args
  27. if (( words[(I)-m] || words[(I)-M] )); then
  28. dependent_creation_args=
  29. dependent_modification_args=(
  30. ':old or new branch name:__git_branch_names'
  31. '::new branch name:__git_branch_names')
  32. fi
  33. _arguments -w -S -s \
  34. "($c $m $d --no-color :)--color=-[turn on branch coloring]:: :__git_color_whens" \
  35. "($c $m $d : --color)--no-color[turn off branch coloring]" \
  36. "($c $m -a --all)-r[list or delete only remote-tracking branches]" \
  37. "($c $m $d : -r)"{-a,--all}"[list both remote-tracking branches and local branches]" \
  38. "($c $m $d : -v --verbose)"{-v,--verbose}'[show SHA1 and commit subject line for each head]' \
  39. "($c $m $d :)--abbrev=[set minimum SHA1 display-length]: :__git_guard_number length" \
  40. "($c $m $d :)--no-abbrev[do not abbreviate sha1s]" \
  41. "($l $m $d)-l[create the branch's reflog]" \
  42. "($l $m $d -f --force)"{-f,--force}"[force the creation of a new branch]" \
  43. "($l $m $d -t --track)"{-t,--track}"[set up configuration so that pull merges from the start point]" \
  44. "($l $m $d)--no-track[override the branch.autosetupmerge configuration variable]" \
  45. "($l $m $d)--set-upstream[set up configuration so that pull merges]" \
  46. "($l $m $d)--contains=[only list branches which contain the specified commit]: :__git_committishs" \
  47. "($l $m $d)--merged=[only list branches which are fully contained by HEAD]: :__git_committishs" \
  48. "($l $m $d)--no-merged=[do not list branches which are fully contained by HEAD]: :__git_committishs" \
  49. $dependent_creation_args \
  50. "($l $c $d -M)-m[rename a branch and the corresponding reflog]" \
  51. "($l $c $d -m)-M[rename a branch even if the new branch-name already exists]" \
  52. $dependent_modification_args \
  53. "($l $c $m -D)-d[delete a fully merged branch]" \
  54. "($l $c $m -d)-D[delete a branch]" \
  55. $dependent_deletion_args
  56. }
  57. (( $+functions[__git_ignore_line] )) ||
  58. __git_ignore_line () {
  59. declare -a ignored
  60. ignored=()
  61. ((CURRENT > 1)) &&
  62. ignored+=(${line[1,CURRENT-1]//(#m)[\[\]()\\*?#<>~\^]/\\$MATCH})
  63. ((CURRENT < $#line)) &&
  64. ignored+=(${line[CURRENT+1,-1]//(#m)[\[\]()\\*?#<>~\^]/\\$MATCH})
  65. $* -F ignored
  66. }
  67. (( $+functions[__git_ignore_line_inside_arguments] )) ||
  68. __git_ignore_line_inside_arguments () {
  69. declare -a compadd_opts
  70. zparseopts -D -E -a compadd_opts V: J: 1 2 n f X: M: P: S: r: R: q F:
  71. __git_ignore_line $* $compadd_opts
  72. }