Sample Header Ad - 728x90

complete/compgen fails to suggest when options contain ':' (colon)

2 votes
1 answer
74 views
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 
$ foo ba       
bart baze      
$ foo bart     
$ foo h:ba         
$ foo h:ba         <-- No effect
[The manual](https://www.gnu.org/software/bash/manual/html_node/Programmable-Completion-Builtins.html) 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
Asked by Stewart (15651 rep)
Aug 8, 2024, 09:39 AM
Last activity: Aug 8, 2024, 01:10 PM