I’m failing to get complete
to offer full suggestions when the options in ${COMPREPLY[@]}
contain a :
character. Instead, it only offers the prefix that is common to all suggestions.
Here’s an example that works fine:
_foo()
{
local cur=${COMP_WORDS[$COMP_CWORD]}
COMPREPLY=( $(compgen -W "bart baze" -- "$cur" ) )
}
complete -F _foo foo
And here’s how it is used (I never press Enter, only TAB where indicated)
$ foo <tab>
$ foo ba <-- Autocompletes common prefix, good
$ foo ba<tab>
bart baze <-- Suggests options, good
$ foo bar<tab>
$ foo bart <-- Autocompletes the only option, good
But if I prepend something with a :
, like http://
, it fails to provide full suggestions (only the prefix common to all options):
$ _foo()
{
local cur=${COMP_WORDS[$COMP_CWORD]}
COMPREPLY=( $(compgen -W "h:bart h:baze" -- "$cur" ) )
}
$ complete -F _foo foo
$ foo <tab>
$ foo h:ba <-- Autocompletes common prefix, good
$ foo h:ba<tab>
$ foo h:ba <-- No effect
The manual suggests something about -I
working with delimiters, but complete -I -F _foo foo
doesn’t change anything.
If I inspect deeper, it seems to be with how complete -F
interprets ${COMPREPLY[@]}
. compgen
seems to set COMPREPLY
just fine.
$ COMPREPLY=( $(compgen -W "h:bart h:baze" -- h) )
$ for i in "${COMPREPLY[@]}"; do echo "$i"; done
h:bart
h:baze