Skip to main content
Became Hot Network Question
edited title
Source Link
Stewart
  • 16.1k
  • 5
  • 49
  • 101

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

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 aan 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 

I've tried playing with IFS=$'\n\t', but this doesn't seem to affect the behaviour.

The manual also 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 

So it seems like something with how complete -F interprets ${COMPREPLY[@]}

compgen fails to suggest when options contain ':'

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 a 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 

I've tried playing with IFS=$'\n\t', but this doesn't seem to affect the behaviour.

The manual also 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 

So it seems like something with how complete -F interprets ${COMPREPLY[@]}

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

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 
Source Link
Stewart
  • 16.1k
  • 5
  • 49
  • 101

compgen fails to suggest when options contain ':'

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 a 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 

I've tried playing with IFS=$'\n\t', but this doesn't seem to affect the behaviour.

The manual also 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 

So it seems like something with how complete -F interprets ${COMPREPLY[@]}