I am trying to develop an autocomplete or tab-complete feature for my own set of commands.
For example, assume foo is my binary:
CLI>> foo [TAB] [TAB]
It should show the main commands configure
and show
.
Then if I select configure
, it should show the subcommands CM
, DSP
and NPU
:
CLI>> foo [TAB] [TAB]
DSP NPU CM`
I only know how to tab-complete and display for the first level - how can I get the second level as well?
I will place this in /etc/completion.d
.
My Code:
_foo()
{
local cur prev opts
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
words=("${COMP_WORDS[@]}")
cword=$COMP_CWORD
opts="configure show"
}
I'm stuck as how to add sub commands CM
DSP
NPU
under configure
.