_git 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. __gitcomp_file ()
  55. {
  56. emulate -L zsh
  57. local IFS=$'\n'
  58. compset -P '*[=:]'
  59. compadd -Q -p "${2-}" -f -- ${=1} && _ret=0
  60. }
  61. _git ()
  62. {
  63. local _ret=1
  64. () {
  65. emulate -L ksh
  66. local cur cword prev
  67. cur=${words[CURRENT-1]}
  68. prev=${words[CURRENT-2]}
  69. let cword=CURRENT-1
  70. __${service}_main
  71. }
  72. let _ret && _default -S '' && _ret=0
  73. return _ret
  74. }
  75. _git