_git 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #compdef git gitk
  2. # zsh completion wrapper for git
  3. #
  4. # You need git's bash completion script installed somewhere, by default on the
  5. # same directory as this script.
  6. #
  7. # If your script is on ~/.git-completion.sh instead, you can configure it on
  8. # your ~/.zshrc:
  9. #
  10. # zstyle ':completion:*:*:git:*' script ~/.git-completion.sh
  11. #
  12. # The recommended way to install this script is to copy to
  13. # '~/.zsh/completion/_git', and then add the following to your ~/.zshrc file:
  14. #
  15. # fpath=(~/.zsh/completion $fpath)
  16. complete ()
  17. {
  18. # do nothing
  19. return 0
  20. }
  21. zstyle -s ":completion:*:*:git:*" script script
  22. test -z "$script" && script="$(dirname ${funcsourcetrace[1]%:*})"/git-completion.bash
  23. ZSH_VERSION='' . "$script"
  24. __gitcomp ()
  25. {
  26. emulate -L zsh
  27. local cur_="${3-$cur}"
  28. case "$cur_" in
  29. --*=)
  30. ;;
  31. *)
  32. local c IFS=$' \t\n'
  33. local -a array
  34. for c in ${=1}; do
  35. c="$c${4-}"
  36. case $c in
  37. --*=*|*.) ;;
  38. *) c="$c " ;;
  39. esac
  40. array+=("$c")
  41. done
  42. compset -P '*[=:]'
  43. compadd -Q -S '' -p "${2-}" -a -- array && _ret=0
  44. ;;
  45. esac
  46. }
  47. __gitcomp_nl ()
  48. {
  49. emulate -L zsh
  50. local IFS=$'\n'
  51. compset -P '*[=:]'
  52. compadd -Q -S "${4- }" -p "${2-}" -- ${=1} && _ret=0
  53. }
  54. _git ()
  55. {
  56. local _ret=1
  57. () {
  58. emulate -L ksh
  59. local cur cword prev
  60. cur=${words[CURRENT-1]}
  61. prev=${words[CURRENT-2]}
  62. let cword=CURRENT-1
  63. __${service}_main
  64. }
  65. let _ret && _default -S '' && _ret=0
  66. return _ret
  67. }
  68. _git