kislyuk / argcomplete

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

Autcomplete doesn't work on runnable scripts #369

Closed wiz21b closed 1 year ago

wiz21b commented 2 years ago

Hello,

I'm facing an issue I can't fix myself...

This is my environment:

stefan@debian:~/Projects/raingen$ bash --version
GNU bash, version 5.1.4(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

stefan@debian:~/Projects/raingen$ python --version
Python 3.9.2

stefan@debian:~/Projects/raingen$ python3 --version
Python 3.9.2

stefan@debian:~/Projects/raingen$ pip list | grep complete
argcomplete                       2.0.0

This completion works:

stefan@debian:~/Projects/raingen$ python3 hydro.py --[TAB]
--all-series               --cumulative-series        --import-data              --precipitation-per-month  

But it doesn't work if I invoke python instead of python3

stefan@debian:~/Projects/raingen$ python hydro.py --[TAB] !!! doesn't complete !

Moreover, my script is executable:

stefan@debian:~/Projects/raingen$ ls hydro.py 
-rwxr-xr-x 1 stefan stefan 18K Feb 17 09:18 hydro.py

and starts like this

stefan@debian:~/Projects/raingen$ head hydro.py 
#!/usr/bin/env /usr/bin/python3
# PYTHON_ARGCOMPLETE_OK

import argparse
import argcomplete
parser = argparse.ArgumentParser()
parser.add_argument('--map', action='store_true')
parser.add_argument('--all-series', action='store_true')
parser.add_argument('--some-series',  nargs="*")

but this doesn't work either:

stefan@debian:~/Projects/raingen$ ./hydro.py --[TAB] !!! doesn't complete !

Do you know what's going wrong ? I have installed the global autocomplete as explained in your documentation (option --user)... Do you know how I can debug that ? I saw there's some debug code in your scripts but don't know how to use them...

Thanks !

wiz21b commented 2 years ago

I see this:

complete -o bashdefault -o default -o nospace -F _python_argcomplete /home/stefan/Projects/raingen/hydro.py

When I complete with full path like this, it works:

stefan@debian:~/Projects/raingen$ /home/stefan/Projects/raingen/hydro.py -[TAB]
--all-series               --cumulative-series        --help                     --pearson                  --some-series

So this gave me the idea of doing this:

stefan@debian:~/Projects/raingen$ eval "$(register-python-argcomplete ./hydro.py)"
stefan@debian:~/Projects/raingen$ ./hydro.py -[TAB]
--all-series               --cumulative-series        --help  

Which works. So I'm wondering, does the global complete actually works ?

stefan@debian:~/Projects/raingen$ ls ~/.bash_completion.d/
total 8.0K
-rw-r--r-- 1 stefan stefan 4.1K Feb 17 11:17 python-argcomplete

And now,

stefan@debian:~/Projects/raingen$ python3 hydro.py --[TAB]

doesn't work anymore... I'(m lost :-(

evanunderscore commented 2 years ago

Please follow the debugging instructions in the readme: https://github.com/kislyuk/argcomplete/blob/bf16566adcfb2fd0307c6ecdf24304b21b0b5752/README.rst#debugging

If you see no debug output at all with that variable set, then the completion hook is not being invoked for your program.

kislyuk commented 1 year ago

Thanks for your interest in argcomplete. If global completion does not work for you, you're probably not configuring your bash completion correctly, or the version of bash that's running (which is not necessarily what's returned by bash --version) is too old. Please follow the instructions listed by @evanunderscore, and compare your system's behavior to a clean VM/container image install.

Since I'm unable to reproduce your issue, I'm going to close this for now. If you still need help, please feel free to comment or open a new issue.