|
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
|
@@ -3497,24 +3506,41 @@ __git_func_wrap ()
|
3497 | 3506 | $1
|
3498 | 3507 | }
|
3499 | 3508 |
|
3500 |
| -# Setup completion for certain functions defined above by setting common |
3501 |
| -# variables and workarounds. |
3502 |
| -# This is NOT a public function; use at your own risk. |
3503 |
| -__git_complete () |
| 3509 | +___git_complete () |
3504 | 3510 | {
|
3505 | 3511 | local wrapper="__git_wrap${2}"
|
3506 | 3512 | eval "$wrapper () { __git_func_wrap $2 ; }"
|
3507 | 3513 | complete -o bashdefault -o default -o nospace -F $wrapper $1 2>/dev/null \
|
3508 | 3514 | || complete -o default -o nospace -F $wrapper $1
|
3509 | 3515 | }
|
3510 | 3516 |
|
3511 |
| -__git_complete git __git_main |
3512 |
| -__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 |
3513 | 3539 |
|
3514 | 3540 | # The following are necessary only for Cygwin, and only are needed
|
3515 | 3541 | # when the user has tab-completed the executable name and consequently
|
3516 | 3542 | # included the '.exe' suffix.
|
3517 | 3543 | #
|
3518 | 3544 | if [ "$OSTYPE" = cygwin ]; then
|
3519 |
| - __git_complete git.exe __git_main |
| 3545 | + ___git_complete git.exe __git_main |
3520 | 3546 | fi
|
0 commit comments