ShellCompletion

Philipp Erbelding edited this page Oct 3, 2018 · 3 revisions

Bash Completion

The help command takes an optional switch, -c, that will list all the commands (including aliases) in sorted order suitable for use in a bash completion script. When -c is specified, the argument can be a partial command, and help will only list the commands matching. Source this into your bash, for example by putting it in your .bashrc:

    complete -F get_myapp_targets myapp
    function get_myapp_targets() 
    {
        COMPREPLY=(`myapp help -c "${COMP_WORDS[@]:1}"`)
    }

Now, suppose your app takes the commands list, ls, rm, add, and init:

> myapp <TAB>
add init list ls rm
> myapp l<TAB>
list ls

Subcommands like myapp foo [bar|rab] should also work:

> myapp f <TAB>
> myapp foo <TAB><TAB>
bar rab
> myapp foo b<TAB>
> myapp foo bar
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.