1 # bash/zsh completion support for core Git. 2 # 3 # Copyright (C) 2006,2007 Shawn O. Pearce 4 # Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/). 5 # Distributed under the GNU General Public License, version 2.0. 6 # 7 # The contained completion routines provide support for completing: 8 # 9 # *) local and remote branch names 10 # *) local and remote tag names 11 # *) .git/remotes file names 12 # *) git 'subcommands' 13 # *) git email aliases for git-send-email 14 # *) tree paths within 'ref:path/to/file' expressions 15 # *) file paths within current working directory and index 16 # *) common --long-options 17 # 18 # To use these routines: 19 # 20 # 1) Copy this file to somewhere (e.g. ~/.git-completion.bash). 21 # 2) Add the following line to your .bashrc/.zshrc: 22 # source ~/.git-completion.bash 23 # 3) Consider changing your PS1 to also show the current branch, 24 # see git-prompt.sh for details. 25 # 26 # If you use complex aliases of form '!f() { ... }; f', you can use the null 27 # command ':' as the first command in the function body to declare the desired 28 # completion style. For example '!f() { : git commit ; ... }; f' will 29 # tell the completion to use commit completion. This also works with aliases 30 # of form "!sh -c '...'". For example, "!sh -c ': git commit ; ... '". 31 # 32 # Compatible with bash 3.2.57. 33 # 34 # You can set the following environment variables to influence the behavior of 35 # the completion routines: 36 # 37 # GIT_COMPLETION_CHECKOUT_NO_GUESS 38 # 39 # When set to "1", do not include "DWIM" suggestions in git-checkout 40 # completion (e.g., completing "foo" when "origin/foo" exists). 41 42 case "$COMP_WORDBREAKS" in 43 *:*) : great ;; 44 *) COMP_WORDBREAKS="$COMP_WORDBREAKS:" 45 esac 46 47 # Discovers the path to the git repository taking any '--git-dir=' and 48 # '-C ' options into account and stores it in the $__git_repo_path 49 # variable. 50 __git_find_repo_path () 51 { 52 if [ -n "$__git_repo_path" ]; then 53 # we already know where it is 54 return 55 fi 56 57 if [ -n "${__git_C_args-}" ]; then 58 __git_repo_path="$(git "${__git_C_args[@]}" \ 59 ${__git_dir:+--git-dir="$__git_dir"} \ 60 rev-parse --absolute-git-dir 2>/dev/null)" 61 elif [ -n "${__git_dir-}" ]; then 62 test -d "$__git_dir" && 63 __git_repo_path="$__git_dir" 64 elif [ -n "${GIT_DIR-}" ]; then 65 test -d "${GIT_DIR-}" && 66 __git_repo_path="$GIT_DIR" 67 elif [ -d .git ]; then 68 __git_repo_path=.git 69 else 70 __git_repo_path="$(git rev-parse --git-dir 2>/dev/null)" 71 fi 72 } 73 74 # Deprecated: use __git_find_repo_path() and $__git_repo_path instead 75 # __gitdir accepts 0 or 1 arguments (i.e., location) 76 # returns location of .git repo 77 __gitdir () 78 { 79 if [ -z "${1-}" ]; then 80 __git_find_repo_path || return 1 81 echo "$__git_repo_path" 82 elif [ -d "$1/.git" ]; then 83 echo "$1/.git" 84 else 85 echo "$1" 86 fi 87 } 88 89 # Runs git with all the options given as argument, respecting any 90 # '--git-dir=' and '-C ' options present on the command line 91 __git () 92 { 93 git ${__git_C_args:+"${__git_C_args[@]}"} \ 94 ${__git_dir:+--git-dir="$__git_dir"} "$@" 2>/dev/null 95 } 96 97 # Removes backslash escaping, single quotes and double quotes from a word, 98 # stores the result in the variable $dequoted_word. 99 # 1: The word to dequote. 100 __git_dequote () 101 { 102 local rest="$1" len ch 103 104 dequoted_word="" 105 106 while test -n "$rest"; do 107 len=${#dequoted_word} 108 dequoted_word="$dequoted_word${rest%%[\\\'\"]*}" 109 rest="${rest:$((${#dequoted_word}-$len))}" 110 111 case "${rest:0:1}" in 112 \\) 113 ch="${rest:1:1}" 114 case "$ch" in 115 $'\n') 116 ;; 117 *) 118 dequoted_word="$dequoted_word$ch" 119 ;; 120 esac 121 rest="${rest:2}" 122 ;; 123 \') 124 rest="${rest:1}" 125 len=${#dequoted_word} 126 dequoted_word="$dequoted_word${rest%%\'*}" 127 rest="${rest:$((${#dequoted_word}-$len+1))}" 128 ;; 129 \") 130 rest="${rest:1}" 131 while test -n "$rest" ; do 132 len=${#dequoted_word} 133 dequoted_word="$dequoted_word${rest%%[\\\"]*}" 134 rest="${rest:$((${#dequoted_word}-$len))}" 135 case "${rest:0:1}" in 136 \\) 137 ch="${rest:1:1}" 138 case "$ch" in 139 \"|\\|\$|\`) 140 dequoted_word="$dequoted_word$ch" 141 ;; 142 $'\n') 143 ;; 144 *) 145 dequoted_word="$dequoted_word\\$ch" 146 ;; 147 esac 148 rest="${rest:2}" 149 ;; 150 \") 151 rest="${rest:1}" 152 break 153 ;; 154 esac 155 done 156 ;; 157 esac 158 done 159 } 160 161 # The following function is based on code from: 162 # 163 # bash_completion - programmable completion functions for bash 3.2+ 164 # 165 # Copyright © 2006-2008, Ian Macdonald 166 # © 2009-2010, Bash Completion Maintainers 167 # 168 # 169 # This program is free software; you can redistribute it and/or modify 170 # it under the terms of the GNU General Public License as published by 171 # the Free Software Foundation; either version 2, or (at your option) 172 # any later version. 173 # 174 # This program is distributed in the hope that it will be useful, 175 # but WITHOUT ANY WARRANTY; without even the implied warranty of 176 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 177 # GNU General Public License for more details. 178 # 179 # You should have received a copy of the GNU General Public License 180 # along with this program; if not, see . 181 # 182 # The latest version of this software can be obtained here: 183 # 184 # http://bash-completion.alioth.debian.org/ 185 # 186 # RELEASE: 2.x 187 188 # This function can be used to access a tokenized list of words 189 # on the command line: 190 # 191 # __git_reassemble_comp_words_by_ref '=:' 192 # if test "${words_[cword_-1]}" = -w 193 # then 194 # ... 195 # fi 196 # 197 # The argument should be a collection of characters from the list of 198 # word completion separators (COMP_WORDBREAKS) to treat as ordinary 199 # characters. 200 # 201 # This is roughly equivalent to going back in time and setting 202 # COMP_WORDBREAKS to exclude those characters. The intent is to 203 # make option types like --date= and : easy to 204 # recognize by treating each shell word as a single token. 205 # 206 # It is best not to set COMP_WORDBREAKS directly because the value is 207 # shared with other completion scripts. By the time the completion 208 # function gets called, COMP_WORDS has already been populated so local 209 # changes to COMP_WORDBREAKS have no effect. 210 # 211 # Output: words_, cword_, cur_. 212 213 __git_reassemble_comp_words_by_ref() 214 { 215 local exclude i j first 216 # Which word separators to exclude? 217 exclude="${1//[^$COMP_WORDBREAKS]}" 218 cword_=$COMP_CWORD 219 if [ -z "$exclude" ]; then 220 words_=("${COMP_WORDS[@]}") 221 return 222 fi 223 # List of word completion separators has shrunk; 224 # re-assemble words to complete. 225 for ((i=0, j=0; i < ${#COMP_WORDS[@]}; i++, j++)); do 226 # Append each nonempty word consisting of just 227 # word separator characters to the current word. 228 first=t 229 while 230 [ $i -gt 0 ] && 231 [ -n "${COMP_WORDS[$i]}" ] && 232 # word consists of excluded word separators 233 [ "${COMP_WORDS[$i]//[^$exclude]}" = "${COMP_WORDS[$i]}" ] 234 do 235 # Attach to the previous token, 236 # unless the previous token is the command name. 237 if [ $j -ge 2 ] && [ -n "$first" ]; then 238 ((j--)) 239 fi 240 first= 241 words_[$j]=${words_[j]}${COMP_WORDS[i]} 242 if [ $i = $COMP_CWORD ]; then 243 cword_=$j 244 fi 245 if (($i < ${#COMP_WORDS[@]} - 1)); then 246 ((i++)) 247 else 248 # Done. 249 return 250 fi 251 done 252 words_[$j]=${words_[j]}${COMP_WORDS[i]} 253 if [ $i = $COMP_CWORD ]; then 254 cword_=$j 255 fi 256 done 257 } 258 259 if ! type _get_comp_words_by_ref >/dev/null 2>&1; then 260 _get_comp_words_by_ref () 261 { 262 local exclude cur_ words_ cword_ 263 if [ "$1" = "-n" ]; then 264 exclude=$2 265 shift 2 266 fi 267 __git_reassemble_comp_words_by_ref "$exclude" 268 cur_=${words_[cword_]} 269 while [ $# -gt 0 ]; do 270 case "$1" in 271 cur) 272 cur=$cur_ 273 ;; 274 prev) 275 prev=${words_[$cword_-1]} 276 ;; 277 words) 278 words=("${words_[@]}") 279 ;; 280 cword) 281 cword=$cword_ 282 ;; 283 esac 284 shift 285 done 286 } 287 fi 288 289 # Fills the COMPREPLY array with prefiltered words without any additional 290 # processing. 291 # Callers must take care of providing only words that match the current word 292 # to be completed and adding any prefix and/or suffix (trailing space!), if 293 # necessary. 294 # 1: List of newline-separated matching completion words, complete with 295 # prefix and suffix. 296 __gitcomp_direct () 297 { 298 local IFS=$'\n' 299 300 COMPREPLY=($1) 301 } 302 303 __gitcompappend () 304 { 305 local x i=${#COMPREPLY[@]} 306 for x in $1; do 307 if [[ "$x" == "$3"* ]]; then 308 COMPREPLY[i++]="$2$x$4" 309 fi 310 done 311 } 312 313 __gitcompadd () 314 { 315 COMPREPLY=() 316 __gitcompappend "$@" 317 } 318 319 # Generates completion reply, appending a space to possible completion words, 320 # if necessary. 321 # It accepts 1 to 4 arguments: 322 # 1: List of possible completion words. 323 # 2: A prefix to be added to each possible completion word (optional). 324 # 3: Generate possible completion matches for this word (optional). 325 # 4: A suffix to be appended to each possible completion word (optional). 326 __gitcomp () 327 { 328 local cur_="${3-$cur}" 329 330 case "$cur_" in 331 --*=) 332 ;; 333 --no-*) 334 local c i=0 IFS=$' \t\n' 335 for c in $1; do 336 if [[ $c == "--" ]]; then 337 continue 338 fi 339 c="$c${4-}" 340 if [[ $c == "$cur_"* ]]; then 341 case $c in 342 --*=*|*.) ;; 343 *) c="$c " ;; 344 esac 345 COMPREPLY[i++]="${2-}$c" 346 fi 347 done 348 ;; 349 *) 350 local c i=0 IFS=$' \t\n' 351 for c in $1; do 352 if [[ $c == "--" ]]; then 353 c="--no-...${4-}" 354 if [[ $c == "$cur_"* ]]; then 355 COMPREPLY[i++]="${2-}$c " 356 fi 357 break 358 fi 359 c="$c${4-}" 360 if [[ $c == "$cur_"* ]]; then 361 case $c in 362 --*=*|*.) ;; 363 *) c="$c " ;; 364 esac 365 COMPREPLY[i++]="${2-}$c" 366 fi 367 done 368 ;; 369 esac 370 } 371 372 # Clear the variables caching builtins' options when (re-)sourcing 373 # the completion script. 374 if [[ -n ${ZSH_VERSION-} ]]; then 375 unset $(set |sed -ne 's/^\(__gitcomp_builtin_[a-zA-Z0-9_][a-zA-Z0-9_]*\)=.*/\1/p') 2>/dev/null 376 else 377 unset $(compgen -v __gitcomp_builtin_) 378 fi 379 380 # This function is equivalent to 381 # 382 # __gitcomp "$(git xxx --git-completion-helper) ..." 383 # 384 # except that the output is cached. Accept 1-3 arguments: 385 # 1: the git command to execute, this is also the cache key 386 # 2: extra options to be added on top (e.g. negative forms) 387 # 3: options to be excluded 388 __gitcomp_builtin () 389 { 390 # spaces must be replaced with underscore for multi-word 391 # commands, e.g. "git remote add" becomes remote_add. 392 local cmd="$1" 393 local incl="$2" 394 local excl="$3" 395 396 local var=__gitcomp_builtin_"${cmd/-/_}" 397 local options 398 eval "options=\$$var" 399 400 if [ -z "$options" ]; then 401 # leading and trailing spaces are significant to make 402 # option removal work correctly. 403 options=" $(__git ${cmd/_/ } --git-completion-helper) $incl " 404 for i in $excl; do 405 options="${options/ $i / }" 406 done 407 eval "$var=\"$options\"" 408 fi 409 410 __gitcomp "$options" 411 } 412 413 # Variation of __gitcomp_nl () that appends to the existing list of 414 # completion candidates, COMPREPLY. 415 __gitcomp_nl_append () 416 { 417 local IFS=$'\n' 418 __gitcompappend "$1" "${2-}" "${3-$cur}" "${4- }" 419 } 420 421 # Generates completion reply from newline-separated possible completion words 422 # by appending a space to all of them. 423 # It accepts 1 to 4 arguments: 424 # 1: List of possible completion words, separated by a single newline. 425 # 2: A prefix to be added to each possible completion word (optional). 426 # 3: Generate possible completion matches for this word (optional). 427 # 4: A suffix to be appended to each possible completion word instead of 428 # the default space (optional). If specified but empty, nothing is 429 # appended. 430 __gitcomp_nl () 431 { 432 COMPREPLY=() 433 __gitcomp_nl_append "$@" 434 } 435 436 # Fills the COMPREPLY array with prefiltered paths without any additional 437 # processing. 438 # Callers must take care of providing only paths that match the current path 439 # to be completed and adding any prefix path components, if necessary. 440 # 1: List of newline-separated matching paths, complete with all prefix 441 # path componens. 442 __gitcomp_file_direct () 443 { 444 local IFS=$'\n' 445 446 COMPREPLY=($1) 447 448 # use a hack to enable file mode in bash < 4 449 compopt -o filenames +o nospace 2>/dev/null || 450 compgen -f /non-existing-dir/ >/dev/null || 451 true 452 } 453 454 # Generates completion reply with compgen from newline-separated possible 455 # completion filenames. 456 # It accepts 1 to 3 arguments: 457 # 1: List of possible completion filenames, separated by a single newline. 458 # 2: A directory prefix to be added to each possible completion filename 459 # (optional). 460 # 3: Generate possible completion matches for this word (optional). 461 __gitcomp_file () 462 { 463 local IFS=$'\n' 464 465 # XXX does not work when the directory prefix contains a tilde, 466 # since tilde expansion is not applied. 467 # This means that COMPREPLY will be empty and Bash default 468 # completion will be used. 469 __gitcompadd "$1" "${2-}" "${3-$cur}" "" 470 471 # use a hack to enable file mode in bash < 4 472 compopt -o filenames +o nospace 2>/dev/null || 473 compgen -f /non-existing-dir/ >/dev/null || 474 true 475 } 476 477 # Execute 'git ls-files', unless the --committable option is specified, in 478 # which case it runs 'git diff-index' to find out the files that can be 479 # committed. It return paths relative to the directory specified in the first 480 # argument, and using the options specified in the second argument. 481 __git_ls_files_helper () 482 { 483 if [ "$2" == "--committable" ]; then 484 __git -C "$1" -c core.quotePath=false diff-index \ 485 --name-only --relative HEAD -- "${3//\\/\\\\}*" 486 else 487 # NOTE: $2 is not quoted in order to support multiple options 488 __git -C "$1" -c core.quotePath=false ls-files \ 489 --exclude-standard $2 -- "${3//\\/\\\\}*" 490 fi 491 } 492 493 494 # __git_index_files accepts 1 or 2 arguments: 495 # 1: Options to pass to ls-files (required). 496 # 2: A directory path (optional). 497 # If provided, only files within the specified directory are listed. 498 # Sub directories are never recursed. Path must have a trailing 499 # slash. 500 # 3: List only paths matching this path component (optional). 501 __git_index_files () 502 { 503 local root="$2" match="$3" 504 505 __git_ls_files_helper "$root" "$1" "$match" | 506 awk -F / -v pfx="${2//\\/\\\\}" '{ 507 paths[$1] = 1 508 } 509 END { 510 for (p in paths) { 511 if (substr(p, 1, 1) != "\"") { 512 # No special characters, easy! 513 print pfx p 514 continue 515 } 516 517 # The path is quoted. 518 p = dequote(p) 519 if (p == "") 520 continue 521 522 # Even when a directory name itself does not contain 523 # any special characters, it will still be quoted if 524 # any of its (stripped) trailing path components do. 525 # Because of this we may have seen the same direcory 526 # both quoted and unquoted. 527 if (p in paths) 528 # We have seen the same directory unquoted, 529 # skip it. 530 continue 531 else 532 print pfx p 533 } 534 } 535 function dequote(p, bs_idx, out, esc, esc_idx, dec) { 536 # Skip opening double quote. 537 p = substr(p, 2) 538 539 # Interpret backslash escape sequences. 540 while ((bs_idx = index(p, "\\")) != 0) { 541 out = out substr(p, 1, bs_idx - 1) 542 esc = substr(p, bs_idx + 1, 1) 543 p = substr(p, bs_idx + 2) 544 545 if ((esc_idx = index("abtvfr\"\\", esc)) != 0) { 546 # C-style one-character escape sequence. 547 out = out substr("\a\b\t\v\f\r\"\\", 548 esc_idx, 1) 549 } else if (esc == "n") { 550 # Uh-oh, a newline character. 551 # We cant reliably put a pathname 552 # containing a newline into COMPREPLY, 553 # and the newline would create a mess. 554 # Skip this path. 555 return "" 556 } else { 557 # Must be a \nnn octal value, then. 558 dec = esc * 64 + \ 559 substr(p, 1, 1) * 8 + \ 560 substr(p, 2, 1) 561 out = out sprintf("%c", dec) 562 p = substr(p, 3) 563 } 564 } 565 # Drop closing double quote, if there is one. 566 # (There isnt any if this is a directory, as it was 567 # already stripped with the trailing path components.) 568 if (substr(p, length(p), 1) == "\"") 569 out = out substr(p, 1, length(p) - 1) 570 else 571 out = out p 572 573 return out 574 }' 575 } 576 577 # __git_complete_index_file requires 1 argument: 578 # 1: the options to pass to ls-file 579 # 580 # The exception is --committable, which finds the files appropriate commit. 581 __git_complete_index_file () 582 { 583 local dequoted_word pfx="" cur_ 584 585 __git_dequote "$cur" 586 587 case "$dequoted_word" in 588 ?*/*) 589 pfx="${dequoted_word%/*}/" 590 cur_="${dequoted_word##*/}" 591 ;; 592 *) 593 cur_="$dequoted_word" 594 esac 595 596 __gitcomp_file_direct "$(__git_index_files "$1" "$pfx" "$cur_")" 597 } 598 599 # Lists branches from the local repository. 600 # 1: A prefix to be added to each listed branch (optional). 601 # 2: List only branches matching this word (optional; list all branches if 602 # unset or empty). 603 # 3: A suffix to be appended to each listed branch (optional). 604 __git_heads () 605 { 606 local pfx="${1-}" cur_="${2-}" sfx="${3-}" 607 608 __git for-each-ref --format="${pfx//\%/%%}%(refname:strip=2)$sfx" \ 609 "refs/heads/$cur_*" "refs/heads/$cur_*/**" 610 } 611 612 # Lists tags from the local repository. 613 # Accepts the same positional parameters as __git_heads() above. 614 __git_tags () 615 { 616 local pfx="${1-}" cur_="${2-}" sfx="${3-}" 617 618 __git for-each-ref --format="${pfx//\%/%%}%(refname:strip=2)$sfx" \ 619 "refs/tags/$cur_*" "refs/tags/$cur_*/**" 620 } 621 622 # Lists refs from the local (by default) or from a remote repository. 623 # It accepts 0, 1 or 2 arguments: 624 # 1: The remote to list refs from (optional; ignored, if set but empty). 625 # Can be the name of a configured remote, a path, or a URL. 626 # 2: In addition to local refs, list unique branches from refs/remotes/ for 627 # 'git checkout's tracking DWIMery (optional; ignored, if set but empty). 628 # 3: A prefix to be added to each listed ref (optional). 629 # 4: List only refs matching this word (optional; list all refs if unset or 630 # empty). 631 # 5: A suffix to be appended to each listed ref (optional; ignored, if set 632 # but empty). 633 # 634 # Use __git_complete_refs() instead. 635 __git_refs () 636 { 637 local i hash dir track="${2-}" 638 local list_refs_from=path remote="${1-}" 639 local format refs 640 local pfx="${3-}" cur_="${4-$cur}" sfx="${5-}" 641 local match="${4-}" 642 local fer_pfx="${pfx//\%/%%}" # "escape" for-each-ref format specifiers 643 644 __git_find_repo_path 645 dir="$__git_repo_path" 646 647 if [ -z "$remote" ]; then 648 if [ -z "$dir" ]; then 649 return 650 fi 651 else 652 if __git_is_configured_remote "$remote"; then 653 # configured remote takes precedence over a 654 # local directory with the same name 655 list_refs_from=remote 656 elif [ -d "$remote/.git" ]; then 657 dir="$remote/.git" 658 elif [ -d "$remote" ]; then 659 dir="$remote" 660 else 661 list_refs_from=url 662 fi 663 fi 664 665 if [ "$list_refs_from" = path ]; then 666 if [[ "$cur_" == ^* ]]; then 667 pfx="$pfx^" 668 fer_pfx="$fer_pfx^" 669 cur_=${cur_#^} 670 match=${match#^} 671 fi 672 case "$cur_" in 673 refs|refs/*) 674 format="refname" 675 refs=("$match*" "$match*/**") 676 track="" 677 ;; 678 *) 679 for i in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD REBASE_HEAD; do 680 case "$i" in 681 $match*) 682 if [ -e "$dir/$i" ]; then 683 echo "$pfx$i$sfx" 684 fi 685 ;; 686 esac 687 done 688 format="refname:strip=2" 689 refs=("refs/tags/$match*" "refs/tags/$match*/**" 690 "refs/heads/$match*" "refs/heads/$match*/**" 691 "refs/remotes/$match*" "refs/remotes/$match*/**") 692 ;; 693 esac 694 __git_dir="$dir" __git for-each-ref --format="$fer_pfx%($format)$sfx" \ 695 "${refs[@]}" 696 if [ -n "$track" ]; then 697 # employ the heuristic used by git checkout 698 # Try to find a remote branch that matches the completion word 699 # but only output if the branch name is unique 700 __git for-each-ref --format="$fer_pfx%(refname:strip=3)$sfx" \ 701 --sort="refname:strip=3" \ 702 "refs/remotes/*/$match*" "refs/remotes/*/$match*/**" | \ 703 uniq -u 704 fi 705 return 706 fi 707 case "$cur_" in 708 refs|refs/*) 709 __git ls-remote "$remote" "$match*" | \ 710 while read -r hash i; do 711 case "$i" in 712 *^{}) ;; 713 *) echo "$pfx$i$sfx" ;; 714 esac 715 done 716 ;; 717 *) 718 if [ "$list_refs_from" = remote ]; then 719 case "HEAD" in 720 $match*) echo "${pfx}HEAD$sfx" ;; 721 esac 722 __git for-each-ref --format="$fer_pfx%(refname:strip=3)$sfx" \ 723 "refs/remotes/$remote/$match*" \ 724 "refs/remotes/$remote/$match*/**" 725 else 726 local query_symref 727 case "HEAD" in 728 $match*) query_symref="HEAD" ;; 729 esac 730 __git ls-remote "$remote" $query_symref \ 731 "refs/tags/$match*" "refs/heads/$match*" \ 732 "refs/remotes/$match*" | 733 while read -r hash i; do 734 case "$i" in 735 *^{}) ;; 736 refs/*) echo "$pfx${i#refs/*/}$sfx" ;; 737 *) echo "$pfx$i$sfx" ;; # symbolic refs 738 esac 739 done 740 fi 741 ;; 742 esac 743 } 744 745 # Completes refs, short and long, local and remote, symbolic and pseudo. 746 # 747 # Usage: __git_complete_refs [