2
_example()
{
    local cur prev

    cur="${COMP_WORDS[COMP_CWORD]}"
    prev="${COMP_WORDS[COMP_CWORD-1]}"

    if [[ ${prev} == example ]] ; then
        COMPREPLY=( $(compgen -W "git" -- ${cur}) )
    elif [[ ${prev} == git ]] ; then
        _command
    elif [[ ${prev} == g ]] ; then
        # ??? TODO 
        # I want the same completion for `example git <TAB>` and `example g <TAB>`
    else
        COMPREPLY=()
    fi
    return 0
}
complete -F _example example

I know how to "call" bash-completion for next command. (code above)
eg.: example git <TAB> => completion for git

How to make bash-completion that "calls" any completion I want for next command?
eg.: example g <TAB> => completion for git

1 Answer 1

2

Populate COMP_CWORD, COMP_WORDS, and COMP_LINE, and then call git's completion function __git_wrap__git_main.

For an example of populating COMP_* and invoking a pre-defined completion function, see this.

For more on figuring out how git completes, you might want to start here.

Sign up to request clarification or add additional context in comments.

1 Comment

Yes, refer to second paragraph of answer and the link therein.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.