* Fix fish for ShellDirectiveNoSpace and file comp
For fish shell we achieve ShellDirectiveNoSpace by outputing a fake
second completion with an extra character. However, this extra
character was being added after the description string, instead of
before. This commit fixes that.
It also cleans up the script of useless code, now that fish completion
details are better understood.
Signed-off-by: Marc Khouzam <marc.khouzam@montreal.ca>
* Handle case when completion starts with a space
Fixes#1303
Signed-off-by: Marc Khouzam <marc.khouzam@montreal.ca>
* Support fish completion with env vars in the path
Fixes https://github.com/spf13/cobra/issues/1214
Fixes https://github.com/spf13/cobra/issues/1306
Signed-off-by: Marc Khouzam <marc.khouzam@montreal.ca>
* Update based on review
1- We use `set -l` for local variable to make sure there are no
conflicts with global variables
2- We use `commandline -opc` which:
a) splits the command line into tokens (-o)
b) only considers the current command (-p) (e.g., echo hello; helm <TAB>)
c) stops at the cursor (-c)
3- We extract the last arg with `commandline -ct` and escape it to handle
the case where it is a space, or unmatched quote.
4- We avoid looping when filtering on prefix.
5- We don't add a fake comp for ShellCompDirectiveNoSpace when the
completion ends with any of @=/:., as fish won't add a space
Signed-off-by: Marc Khouzam <marc.khouzam@montreal.ca>
Some programs may output extra empty lines after the directive.
Those lines must be ignored for fish shell completion to work.
zsh and bash are not impacted.
Signed-off-by: Marc Khouzam <marc.khouzam@montreal.ca>
Co-authored-by: Johannes Altmanninger <aclopte@gmail.com>
Co-authored-by: Johannes Altmanninger <aclopte@gmail.com>
Replace the current Zsh completion with a Zsh completion solution based
on Go completions. This allows to support custom completions (based
on Go completions), but also to standardize the behavior of completion
across all shells.
Also, add support to Go completions for the bash completion annotations:
BashCompFilenameExt (including Command.MarkFlagFilename() family)
- still supported by zsh
BashCompSubdirsInDir - now supported by zsh
BashCompOneRequiredFlag (including Command.MarkFlagRequired() family)
- now supported by zsh and fish
Finally, remove the suggestin of the = form of flag completion.
The = form is supported, but it will not be suggested to avoid having
duplicated suggestions.