Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/git/blob/master/contrib/completion/git-completion.zsh # git [Ported from github.com/git/git] Sync with Git 2.56.1 Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `git / contrib / completion / git-completion.zsh` 323 lines ยท 7643 bytes Raw Blame History 1 #compdef git gitk 2 3 # zsh completion wrapper for git 4 # 5 # Copyright (c) 2012-2020 Felipe Contreras 6 # 7 # The recommended way to install this script is to make a copy of it as a 8 # file named '_git' inside any directory in your fpath. 9 # 10 # For example, create a directory '~/.zsh/', copy this file to '~/.zsh/_git', 11 # and then add the following to your ~/.zshrc file: 12 # 13 # fpath=(~/.zsh $fpath) 14 # 15 # You need git's bash completion script installed. By default bash-completion's 16 # location will be used (e.g. pkg-config --variable=completionsdir bash-completion). 17 # 18 # If your bash completion script is somewhere else, you can specify the 19 # location in your ~/.zshrc: 20 # 21 # zstyle ':completion:*:*:git:*' script ~/.git-completion.bash 22 # 23 24 zstyle -T ':completion:*:*:git:*' tag-order && \ 25 zstyle ':completion:*:*:git:*' tag-order 'common-commands' 26 27 zstyle -s ":completion:*:*:git:*" script script 28 if [ -z "$script" ]; then 29 local -a locations 30 local e bash_completion 31 32 bash_completion=$(pkg-config --variable=completionsdir bash-completion 2>/dev/null) || 33 bash_completion='/usr/share/bash-completion/completions/' 34 35 locations=( 36 "$(dirname ${funcsourcetrace[1]%:*})"/git-completion.bash 37 "$HOME/.local/share/bash-completion/completions/git" 38 "$bash_completion/git" 39 '/etc/bash_completion.d/git' # old debian 40 ) 41 for e in $locations; do 42 test -f $e && script="$e" && break 43 done 44 fi 45 46 local old_complete="$functions[complete]" 47 functions[complete]=: 48 GIT_SOURCING_ZSH_COMPLETION=y . "$script" 49 functions[complete]="$old_complete" 50 51 __gitcomp () 52 { 53 emulate -L zsh 54 55 local cur_="${3-$cur}" 56 57 case "$cur_" in 58 --*=) 59 ;; 60 --no-*) 61 local c IFS=$' \t\n' 62 local -a array 63 for c in ${=1}; do 64 if [[ $c == "--" ]]; then 65 continue 66 fi 67 c="$c${4-}" 68 case $c in 69 --*=|*.) ;; 70 *) c="$c " ;; 71 esac 72 array+=("$c") 73 done 74 compset -P '*[=:]' 75 compadd -Q -S '' -p "${2-}" -a -- array && _ret=0 76 ;; 77 *) 78 local c IFS=$' \t\n' 79 local -a array 80 for c in ${=1}; do 81 if [[ $c == "--" ]]; then 82 c="--no-...${4-}" 83 array+=("$c ") 84 break 85 fi 86 c="$c${4-}" 87 case $c in 88 --*=|*.) ;; 89 *) c="$c " ;; 90 esac 91 array+=("$c") 92 done 93 compset -P '*[=:]' 94 compadd -Q -S '' -p "${2-}" -a -- array && _ret=0 95 ;; 96 esac 97 } 98 99 __gitcomp_direct () 100 { 101 emulate -L zsh 102 103 compset -P '*[=:]' 104 compadd -Q -S '' -- ${(f)1} && _ret=0 105 } 106 107 __gitcomp_nl () 108 { 109 emulate -L zsh 110 111 compset -P '*[=:]' 112 compadd -Q -S "${4- }" -p "${2-}" -- ${(f)1} && _ret=0 113 } 114 115 __gitcomp_file () 116 { 117 emulate -L zsh 118 119 compset -P '*[=:]' 120 compadd -f -p "${2-}" -- ${(f)1} && _ret=0 121 } 122 123 __gitcomp_direct_append () 124 { 125 __gitcomp_direct "$@" 126 } 127 128 __gitcomp_nl_append () 129 { 130 __gitcomp_nl "$@" 131 } 132 133 __gitcomp_file_direct () 134 { 135 __gitcomp_file "$1" "" 136 } 137 138 __git_complete_stashes () 139 { 140 compadd -S ' ' -- ${(f)"$(__git stash list | sed -n -e 's/:.*//p')"} && _ret=0 141 } 142 143 _git_zsh () 144 { 145 __gitcomp "v1.1" 146 } 147 148 __git_complete_command () 149 { 150 emulate -L zsh 151 152 local command="$1" 153 local completion_func="_git_${command//-/_}" 154 if (( $+functions[$completion_func] )); then 155 emulate ksh -c $completion_func 156 return 0 157 else 158 return 1 159 fi 160 } 161 162 __git_zsh_bash_func () 163 { 164 emulate -L ksh 165 166 local command=$1 167 168 __git_complete_command "$command" && return 169 170 local expansion=$(__git_aliased_command "$command") 171 if [ -n "$expansion" ]; then 172 words[1]=$expansion 173 __git_complete_command "$expansion" 174 fi 175 } 176 177 __git_zsh_cmd_common () 178 { 179 local -a list 180 list=( 181 add:'add file contents to the index' 182 bisect:'find by binary search the change that introduced a bug' 183 branch:'list, create, or delete branches' 184 checkout:'checkout a branch or paths to the working tree' 185 clone:'clone a repository into a new directory' 186 commit:'record changes to the repository' 187 diff:'show changes between commits, commit and working tree, etc' 188 fetch:'download objects and refs from another repository' 189 grep:'print lines matching a pattern' 190 init:'create an empty Git repository or reinitialize an existing one' 191 log:'show commit logs' 192 merge:'join two or more development histories together' 193 mv:'move or rename a file, a directory, or a symlink' 194 pull:'fetch from and merge with another repository or a local branch' 195 push:'update remote refs along with associated objects' 196 rebase:'forward-port local commits to the updated upstream head' 197 reset:'reset current HEAD to the specified state' 198 restore:'restore working tree files' 199 rm:'remove files from the working tree and from the index' 200 show:'show various types of objects' 201 status:'show the working tree status' 202 switch:'switch branches' 203 tag:'create, list, delete or verify a tag object signed with GPG') 204 _describe -t common-commands 'common commands' list && _ret=0 205 } 206 207 __git_zsh_cmd_alias () 208 { 209 local -a list 210 list=(${(0)"$(git help --aliases-for-completion)"}) 211 list=(${(f)"$(printf "%s:alias for '%s'\n" ${(f@)list})"}) 212 _describe -t alias-commands 'aliases' list && _ret=0 213 } 214 215 __git_zsh_cmd_all () 216 { 217 local -a list 218 emulate ksh -c __git_compute_all_commands 219 list=( ${=__git_all_commands} ) 220 _describe -t all-commands 'all commands' list && _ret=0 221 } 222 223 __git_zsh_main () 224 { 225 local curcontext="$curcontext" state state_descr line 226 typeset -A opt_args 227 local -a orig_words 228 229 orig_words=( ${words[@]} ) 230 231 _arguments -C \ 232 '(-p --paginate --no-pager)'{-p,--paginate}'[pipe all output into ''less'']' \ 233 '(-p --paginate)--no-pager[do not pipe git output into a pager]' \ 234 '--git-dir=-[set the path to the repository]: :_directories' \ 235 '*-C[run as if git was started in ]: :_directories' \ 236 '--bare[treat the repository as a bare repository]' \ 237 '(- :)--version[prints the git suite version]' \ 238 '--exec-path=-[path to where your core git programs are installed]:: :_directories' \ 239 '--html-path[print the path where git''s HTML documentation is installed]' \ 240 '--info-path[print the path where the Info files are installed]' \ 241 '--man-path[print the manpath (see `man(1)`) for the man pages]' \ 242 '--work-tree=-[set the path to the working tree]: :_directories' \ 243 '--namespace=-[set the git namespace]' \ 244 '--no-replace-objects[do not use replacement refs to replace git objects]' \ 245 '(- :)--help[prints the synopsis and a list of the most commonly used commands]: :->arg' \ 246 '(-): :->command' \ 247 '(-)*:: :->arg' && return 248 249 case $state in 250 (command) 251 _tags common-commands alias-commands all-commands 252 while _tags; do 253 _requested common-commands && __git_zsh_cmd_common 254 _requested alias-commands && __git_zsh_cmd_alias 255 _requested all-commands && __git_zsh_cmd_all 256 let _ret || break 257 done 258 ;; 259 (arg) 260 local command="${words[1]}" __git_dir __git_cmd_idx 261 local -a __git_C_args 262 local -i i=2 263 264 while (( i <= $#orig_words )); do 265 case ${orig_words[i]} in 266 -C) 267 __git_C_args+=(-C ${orig_words[i+1]}) 268 (( i++ )) 269 ;; 270 -c|--git-dir|--work-tree|--namespace) 271 (( i++ )) 272 ;; 273 -*) 274 ;; 275 *) 276 break 277 ;; 278 esac 279 (( i++ )) 280 done 281 282 __git_cmd_idx=$(( i - 1 )) 283 284 if (( $+opt_args[--bare] )); then 285 __git_dir='.' 286 else 287 __git_dir=${opt_args[--git-dir]} 288 fi 289 290 (( $+opt_args[--help] )) && command='help' 291 292 words=( ${orig_words[@]} ) 293 294 __git_zsh_bash_func $command 295 ;; 296 esac 297 } 298 299 _git () 300 { 301 local _ret=1 302 local cur cword prev 303 local __git_repo_path 304 305 cur=${words[CURRENT]} 306 prev=${words[CURRENT-1]} 307 let cword=CURRENT-1 308 309 if (( $+functions[__${service}_zsh_main] )); then 310 __${service}_zsh_main 311 elif (( $+functions[__${service}_main] )); then 312 emulate ksh -c __${service}_main 313 elif (( $+functions[_${service}] )); then 314 emulate ksh -c _${service} 315 elif (( $+functions[_${service//-/_}] )); then 316 emulate ksh -c _${service//-/_} 317 fi 318 319 let _ret && _default && _ret=0 320 return _ret 321 } 322 323 _git