|
29 | 29 | # tell the completion to use commit completion. This also works with aliases
|
30 | 30 | # of form "!sh -c '...'". For example, "!sh -c ': git commit ; ... '".
|
31 | 31 | #
|
| 32 | +# If you have a command that is not part of git, but you would still |
| 33 | +# like completion, you can use __git_complete: |
| 34 | +# |
| 35 | +# __git_complete gl git_log |
| 36 | +# |
| 37 | +# Or if it's a main command (i.e. git or gitk): |
| 38 | +# |
| 39 | +# __git_complete gk gitk |
| 40 | +# |
32 | 41 | # Compatible with bash 3.2.57.
|
33 | 42 | #
|
34 | 43 | # You can set the following environment variables to influence the behavior of
|
@@ -3358,15 +3367,19 @@ __git_support_parseopt_helper () {
|
3358 | 3367 | esac
|
3359 | 3368 | }
|
3360 | 3369 |
|
| 3370 | +__git_have_func () { |
| 3371 | + declare -f -- "$1" >/dev/null 2>&1 |
| 3372 | +} |
| 3373 | + |
3361 | 3374 | __git_complete_command () {
|
3362 | 3375 | local command="$1"
|
3363 | 3376 | local completion_func="_git_${command//-/_}"
|
3364 |
| - if ! declare -f $completion_func >/dev/null 2>/dev/null && |
3365 |
| - declare -f _completion_loader >/dev/null 2>/dev/null |
| 3377 | + if ! __git_have_func $completion_func && |
| 3378 | + __git_have_func _completion_loader |
3366 | 3379 | then
|
3367 | 3380 | _completion_loader "git-$command"
|
3368 | 3381 | fi
|
3369 |
| - if declare -f $completion_func >/dev/null 2>/dev/null |
| 3382 | + if __git_have_func $completion_func |
3370 | 3383 | then
|
3371 | 3384 | $completion_func
|
3372 | 3385 | return 0
|
@@ -3493,24 +3506,41 @@ __git_func_wrap ()
|
3493 | 3506 | $1
|
3494 | 3507 | }
|
3495 | 3508 |
|
3496 |
| -# Setup completion for certain functions defined above by setting common |
3497 |
| -# variables and workarounds. |
3498 |
| -# This is NOT a public function; use at your own risk. |
3499 |
| -__git_complete () |
| 3509 | +___git_complete () |
3500 | 3510 | {
|
3501 | 3511 | local wrapper="__git_wrap${2}"
|
3502 | 3512 | eval "$wrapper () { __git_func_wrap $2 ; }"
|
3503 | 3513 | complete -o bashdefault -o default -o nospace -F $wrapper $1 2>/dev/null \
|
3504 | 3514 | || complete -o default -o nospace -F $wrapper $1
|
3505 | 3515 | }
|
3506 | 3516 |
|
3507 |
| -__git_complete git __git_main |
3508 |
| -__git_complete gitk __gitk_main |
| 3517 | +# Setup the completion for git commands |
| 3518 | +# 1: command or alias |
| 3519 | +# 2: function to call (e.g. `git`, `gitk`, `git_fetch`) |
| 3520 | +__git_complete () |
| 3521 | +{ |
| 3522 | + local func |
| 3523 | + |
| 3524 | + if __git_have_func $2; then |
| 3525 | + func=$2 |
| 3526 | + elif __git_have_func __$2_main; then |
| 3527 | + func=__$2_main |
| 3528 | + elif __git_have_func _$2; then |
| 3529 | + func=_$2 |
| 3530 | + else |
| 3531 | + echo "ERROR: could not find function '$2'" 1>&2 |
| 3532 | + return 1 |
| 3533 | + fi |
| 3534 | + ___git_complete $1 $func |
| 3535 | +} |
| 3536 | + |
| 3537 | +___git_complete git __git_main |
| 3538 | +___git_complete gitk __gitk_main |
3509 | 3539 |
|
3510 | 3540 | # The following are necessary only for Cygwin, and only are needed
|
3511 | 3541 | # when the user has tab-completed the executable name and consequently
|
3512 | 3542 | # included the '.exe' suffix.
|
3513 | 3543 | #
|
3514 | 3544 | if [ "$OSTYPE" = cygwin ]; then
|
3515 |
| - __git_complete git.exe __git_main |
| 3545 | + ___git_complete git.exe __git_main |
3516 | 3546 | fi
|
0 commit comments