Inconsistent completion when using a custom validator between `fish` and `bash`
Opened this issue · 1 comments
Code Sample for Reproduction:
#!/usr/bin/env /home/vivek/pyscripts/.direnv/python-3.10.12/bin/python
# PYTHON_ARGCOMPLETE_OK
import argparse
import argcomplete
def complete_foo(prefix, parsed_args, **kwargs):
return ['foo', 'foobar', 'foo1', 'foo2', 'red']
def default_validator(completion_candidate, current_input):
return completion_candidate.startswith(current_input)
def custom_validator(completion_candidate, current_input):
if current_input == "x":
return True
return default_validator(completion_candidate, current_input)
parser = argparse.ArgumentParser()
parser.add_argument('foo').completer = complete_foo # pyright: ignore[reportAttributeAccessIssue]
argcomplete.autocomplete(parser, validator=custom_validator)
args = parser.parse_args()
To register completions on bash, I do
chmod +x
eval "$(register-python-argcomplete mycommand.py)"
And for fish I run
register-python-argcomplete --shell fish /path/to/mycommand.py | source
On bash, when I type ./mycommand.py x<TAB>
I get:
This is the desired result, that I would also like to get in my fish completion, however on fish I get:
Basically, no matches.
Upon more experimentation it seems that the fish completion script seems to be adding it's own startswith
type check, thus overriding the custom validator.
Is there a way to modify the generated fish completion script to remove this behavior?
I'm not sure exactly what you mean when you say "the fish completion script seems to be adding it's own startswith type check, thus overriding the custom validator." This is the code we're generating:
argcomplete/argcomplete/shell_integration.py
Lines 95 to 112 in 6c9e540
My guess would be fish's own machinery is filtering returned completions by prefix. I'm not familiar enough with fish to know if there's an option to change this. It's possible the shell simply doesn't allow it.