fix(complete): Handle COMP_WORDBREAKS colon splitting in bash#6311
fix(complete): Handle COMP_WORDBREAKS colon splitting in bash#6311casey wants to merge 2 commits intoclap-rs:masterfrom
Conversation
Bash's COMP_WORDBREAKS includes `:` by default, which causes COMP_WORDS to split tokens like `foo::bar` into `["foo", ":", ":", "bar"]`. This breaks completion for any value containing colons. Use `_get_comp_words_by_ref -n :` from the bash-completion package to get unsplit words, and `__ltrim_colon_completions` to trim the colon prefix from COMPREPLY so bash replaces text correctly. Both calls are guarded so the script falls back to the current behavior when bash-completion is not installed.
4988f2e to 426e0c2 Compare | Sorry, I ran the tests locally, but didn't run into this error. I'm going to convert this PR to a draft while I debug. |
| Overall, we are wanting to disable |
| I don't think this is the right approach anymore. The functions this PR depend on are from For now, in |
Fixes completion of values containing
:in Bash with theunstable-dynamiccompletion engine.I ran into this while migrating just to use the new dynamic completion engine. Paths to recipes in submodules contain colons
foo::bar, and would break with the new completion engine. We patched the old bash completion script to work around this, but that was a nightmare to maintain, so I'm hoping to upstream this.I think this should be the default behavior, since splitting on
:is not desirable, and no other shell does it.Bash's COMP_WORDBREAKS includes
:by default, which causes COMP_WORDS to split tokens likefoo::barinto["foo", ":", ":", "bar"]. This breaks completion for any value containing colons.Use
_get_comp_words_by_ref -n :to get unsplit words, and__ltrim_colon_completionsto trim the colon prefix from COMPREPLY so bash replaces text correctly._get_comp_words_by_refand__ltrim_colon_completionsare from bash-completion, a pretty commonly available package.Both calls are guarded so the script falls back to the current behavior when bash-completion is not installed.
This was manually test on MacOS using
bashandbash-completion@2installed with homebrew, and it was able to completejust foo::<tab>withjust foo::bar, which fails without this patch.