-
Notifications
You must be signed in to change notification settings - Fork 102
ShellCompletion
Philipp Erbelding edited this page Oct 3, 2018
·
3 revisions
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