Skip to content
davetron5000 edited this page Dec 21, 2010 · 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. Put this in your .bashrc:

    complete -F get_myapp_targets myapp
    function get_myapp_targets() 
    {
        if [ -z $2 ] ; then
            COMPREPLY=(`myapp help -c`)
        else
            COMPREPLY=(`myapp help -c $2`)
        fi
    }

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
Clone this wiki locally