Open kangasta opened 2 years ago
@scop, you may have some expertise on this. Do you have special handling if a completion has a space in it for bash?
Hi @kangasta ;)
It's annoyingly difficult in bash.
A cheap generic way is to fake the completions to be filenames. That does take care of the escaping, but it's obviously semantically incorrect for completions that really aren't filenames. And it may have side effects.
Another one is to run the strings through printf %q ...
here and there in the completion code. Some related discussion e.g. at https://stackoverflow.com/questions/26509260/bash-tab-completion-with-spaces
Anyway I believe neither of these options is currently available for cobra users. I'll have a quick peek at PR #1743.
The Cobra project currently lacks enough contributors to adequately respond to all issues. This bot triages issues and PRs according to the following rules:
Rebased related PR and added comment there as well: #1743
The Cobra project currently lacks enough contributors to adequately respond to all issues. This bot triages issues and PRs according to the following rules:
Adding a comment to keep this from being closed.
I ran across this the other day. This isn't just limited to whitespace, but all characters that need escaping in bash. My completions were using >
, which is kinda unfortunate because cobra started redirecting output to random places during completion
Other shell completions escape whitespace in completions, but bash completions seems to add completions with whitespace as multiple suggestions or multiple arguments depending on bash version. I would expect also bash completions to escape whitespace in completions from
ValidArgsFunction
.bash v3:
bash v4 & v5
fish:
zsh:
powershell
Minimal code to reproduce above usage with
github.com/spf13/cobra v1.5.0
(Gist):