-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a way to bypass the terminal autocomplete matching #1828
Comments
Hi @raphaelvigee. Fuzzy matching is already possible for However, this only works for Finally, for completeness, be aware Cobra does filter on the prefix when it does completion itself. For instance, when completion subcommands and flag names. I have been hesitant to change that as I am not convinced it is a common scenario. |
I can confirm that fuzzy matching does not work on zsh, the situation highlighted above returns no completion in the terminal as they get filtered out in From the zsh debug:
A similar thing is happening with bash I don't have an example in mind that does fuzzy matching, but for my current use-case, fuzzy matching is almost necessary, basically: |
For fuzzy matching to work for
You can try it by running:
This article explains it well: https://thevaluable.dev/zsh-completion-guide-examples/ As for |
I do have this matcher in:
But i feel like we should be able to make the matching handled by cobra user-code and not whatever shell I am using. |
I would expect your example to work with zsh in that case.
That would be great. I'm just not aware if you can get the different shells to do what you want. |
Same, but zsh does not seem to agree as per the logs in #1828 (comment)
Well it would be best effort, if some shell doesn't support it, so be it, prefix matching it is! |
In case it helps, you can at least verify what Cobra sends the shell as completion choices like this:
That's kind of what Cobra does now. If the program returns completion choices that are not filtered on prefix, then zsh and fish will do fuzzy matching if the user has configured the shell to do it. |
Cobra returns the right value
Well yes and no, it does relies on the user having the right matchers configured (and zsh behaving correctly) To try and move this forward, would it be acceptable to add a new directive to bypass the shell matching altogether ? |
If the final solution is more flexible than what we have now and that the way to use this new solution is user-friendly, then yes, no problem adding a new directive. PR welcome. |
The Cobra project currently lacks enough contributors to adequately respond to all issues. This bot triages issues and PRs according to the following rules:
|
This would allow to support fuzzy completions:
Lets say
ValidArgsFunction
return[]string{"some_arg", "some_arg_thats_long"}
I should be presented with the autocomplete options:
Currently those would be filtered out because of the use of
compgen
on bash and_describe
on zsh (haven't checked fish) those will be filtered out as the default behavior is to filter based on prefix.The addition of another directive
ShellCompDirectiveNoMatching
(something like that) would disable the matchingThe text was updated successfully, but these errors were encountered: