Yes, but you need a bit of bash kung foo in order to build such system. The way completion usually works is by binding normal functions to the commands you want to complete. You can find some basic examples around to better understand how completion works, and start developing your completion functions. Also, if you happen to have the bash-completion
package installed, you could search your system for a number of other examples that currently drive completion in your shell.
You could also have a look at the completion section of the official bash manual.
EDIT
I tried some experiments, and my conclusion is now that you can't do exactly what you're after: bash doesn't support help text next to complete
results. What you can do is to add the legend for the provided completing words. This can be done either in a bash function _myfoo
to be used as complete -F _myfoo
, or a command via complete -C myfoo
, which prints out the legend before completing.
The main difference is that using a function you're bound to Bash, while commands can be written in any language you choose, as long as it's able to set the required environment variables.
Here's a little example:
skuro$ touch ~/bin/myfoo
skuro$ chmod +x ~/bin/myfoo
skuro$ _myfoo(){
> echo "result1 -- number one"
> echo "result2 -- number two"
> local cur prev
> _get_comp_words_by_ref cur prev
> COMPREPLY=( $(compgen -W "result1 result2" "$cur") )
> return 0
> }
skuro$ complete -F _myfoo myfoo
skuro$ myfoo result<TAB>
result1 -- number one
result2 -- number two
result1 result2
telnet routerA
? – Prosimian