Open celynw opened 3 years ago
If Bash continues to register default completion functions, then argcomplete's global completion function isn't actually running. What did you do to install it? It's been a while since I've used this, but from memory I usually test it with eval "$(activate-global-python-argcomplete --dest=-)"
.
I followed the instructions in the README, which was a one-time run of activate-global-python-argcomplete
.
According to my bash history, I also tried
activate-global-python-argcomplete --user
activate-global-python-argcomplete --dest ~/.dotfiles/_local/share/bash-completion/completions/
.The latter contains my custom completion files, as well as python-argcomplete
- I assume that was put there as part of the normal installation but I can't be certain.
Your method seems to work!
I do have to run that for every new shell though - but I can just make .bashrc
do that.
I'll leave this issue open for now since it only seems to be a workaround, but it's definitely useful. Thanks!
I ran into the same issue.
I first tried the explicit (eval) method for my script, which worked fine. Then I tried the global activation without success so far:
$ complete | grep argcomplete
complete -o bashdefault -o default -F _python_argcomplete_global -D
$ complete | grep automatix
complete -F _minimal automatix
$ complete -r automatix
$ complete | grep automatix
$ automatix -<tab>
$ complete | grep automatix
complete -F _minimal automatix
$ eval "$(register-python-argcomplete automatix)"
$ complete | grep automatix
complete -o bashdefault -o default -o nospace -F _python_argcomplete automatix
$ automatix -<tab>
-d -f -h -i -j -p --systems --vars-file
--debug --force --help --interactive --jump-to --print-overview --vars
Seems that the default registration is added at the time I try to tab complete, even if the global activation was already registered. I see also no other default entry in the output of complete
.
Since I have only one script so far I am going to use the explicit method in my bashrc.
When I use the global completion mode, completion does not work. Pressing tab with no arguments it returns a file list of the current directory Pressing tab with a
-
or--
seems to return basepython
completion.But when I register a script directly, it works fine. I seem to have run into the issue mentioned in the docs.
Global mode (doesn't work):
Explicit
eval "$(register-python-argcomplete ./test.py)"
(works):The advice (added in #198) says when this happens try removing the completion with
complete -r ./test.py
. But it's not clear how this solves the problem - Trying this again in the same or a new shell presents the same issue for me. Did I miss something?I also tried specifying the full path to
./test.py
, which doesn't make a difference.
```python #!/usr/bin/env python3 # PYTHON_ARGCOMPLETE_OK import argparse import argcomplete from pathlib import Path if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument("-d", "--directory", type=Path) argcomplete.autocomplete(parser) args = parser.parse_args() print(args) ```test.py
is a pretty minimal example.