kislyuk / argcomplete

Python and tab completion, better together.
https://kislyuk.github.io/argcomplete/
Apache License 2.0
1.39k stars 129 forks source link

completer falls back to Bash filename completion #482

Open meonkeys opened 2 months ago

meonkeys commented 2 months ago

It seems like the completer always falls back to Bash filename completion, even if --no-defaults is used.

I think this is a regression of #366.

Repro

  1. create virtual env: python3 -m venv argcomplete
  2. cd argcomplete
  3. activate virtual env: source bin/activate
  4. install latest argcomplete library: pip install argcomplete (v3.2.3)
  5. install test script in $PATH, make executable
  6. enable tab completion with, e.g. eval "$(register-python-argcomplete --no-defaults mytest-argcomplete)"
  7. type mytest-argcomplete --string Tab

Expected result

No output -- no completer is defined, and --no-defaults was used.

Actual result

Bash default tab completion for the current directory (in my case, the python venv):

bin/        include/    lib/        lib64/      pyvenv.cfg

Environment

Test script

#!/home/user/argcomplete/bin/python3
# PYTHON_ARGCOMPLETE_OK

import argparse, argcomplete

parser = argparse.ArgumentParser()
parser.add_argument('-s', '--string')
argcomplete.autocomplete(parser)
args = parser.parse_args()

Workarounds

Don't hit Tab.

Start typing any string that isn't a prefix of anything in the current folder.

I tried manually setting up completion with complete -o nospace +o default +o bashdefault -F _python_argcomplete mytest-argcomplete or using compopt +o default, compopt +o bashdefault in the completion code, but that seems to break tab completion entirely (nothing completes).