kislyuk / argcomplete

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

register-python-argcomplete - exactly registered name #213

Open DerWeh opened 7 years ago

DerWeh commented 7 years ago

Your documentation says:

Shellcode (only necessary if global completion is not activated - see Global completion below), to be put in e.g. .bashrc:

eval "$(register-python-argcomplete my-awesome-script.py)"

Note that the script name is passed directly to complete, meaning it is only tab completed when invoked exactly as it was registered. The above line will not allow you to complete ./my-awesome-script.py, or /path/to/my-awesome-script.py.

But if I try it sadly is exactly the other way around. Arguments after ./my-awesome-script.py and /path/to/my-awesome-script.py will be completed, after my-awesome-script.py however they won't.

evanunderscore commented 7 years ago

Did you enable global completion? The other two are likely being handled by that and something is going wrong for the one you registered explicitly. Try setting _ARC_DEBUG and see what it says.

DerWeh commented 7 years ago

I did not enable global completion but used register-python-argcomplete. I now separately tried it with global completion, the result was the same (the line after the shebang is # PYTHON_ARGCOMPLETE_OK). I included the debug log. The only example that worked was ./pyplot/pyplot.py configure, the others provided no argument completion.

autocomplete_debug.log.txt autocomplete_debug_global_completion.log.txt

evanunderscore commented 7 years ago

When you say "./my-awesome-script.py and /path/to/my-awesome-script.py will be completed" do you mean they are completing file names? If so, this is the default behavior of your shell for anything that doesn't have a completer - argcomplete is not doing anything.

Can you please attach a minimal script and some instructions on how to reproduce the failure you're seeing?

DerWeh commented 7 years ago

@evanunderscore Sorry for the unclear formulation, for ./my-awesome-script.py and /path/to/my-awesome-script.py the arguments will be properly completed and not file names.

A simply minimum example:

$ chmod +x my-awsome-script.py
$ complete | grep awsome
complete -o default -o nospace -F _python_argcomplete ./my-awsome-script.py
complete -o default -o nospace -F _python_argcomplete /home/user/minimal/my-awsome-script.py
complete -o default -o nospace -F _python_argcomplete my-awsome-script
complete -o default -o nospace -F _python_argcomplete ~/minimal/my-awsome-script.py
$ alias -p my-awsome-script
alias my-awsome-script='/home/user/minimal/my-awsome-script.py'

These where all the variations I tried, however my-awsome-script and ~/minimal/my-awsome-script.py can't be completed. (The .txt ending has obviously to be omitted, it's just for uploading.) I also tried global bash completion, also without any results.

my-awsome-script.py.txt

evanunderscore commented 7 years ago

Sorry for not getting back to you sooner, I didn't notice you had edited your post.

I think you may have misinterpreted the readme in your initial post - it is saying that line verbatim will not allow you to complete ./my-awesome-script.py or /path/to/my-awesome-script.py. That line will also only allow you to complete it as my-awesome-script.py provided that you can run it as my-awesome-script.py, i.e. if it is on your path.

I believe the intent of register-python-argcomplete is to complete something that has been installed and is likely to only ever be run with one name, like git (although @kislyuk may want to correct me here). If that's the case having a .py extension in the example could be a little misleading. Suggestions are welcome for how to word this section of the readme more clearly to avoid the confusion you encountered.


For my-awesome-script, we currently don't do any work to make this work with aliases. If you need this, I'd suggest opening a new issue to request the feature.

For ~/minimal/my-awesome-script.py, this works in global completion but not with register-python-argcomplete. This could be fixed by copying the __python_argcomplete_expand_tilde_by_ref bit from global completion. The reason it appears not to work in global completion for you is the one you registered gets in first and doesn't work. If you try it from a clean shell it should be fine.

DerWeh commented 7 years ago

Thanks for the help, I will try it as soon as I can and see if it works. To the readme:

Note that the script name is passed directly to complete, meaning it is only tab completed when invoked exactly as it was registered. The above line will not allow you to complete ./my-awesome-script.py, or /path/to/my-awesome-script.py.

For me something like:

Note that the script name is passed directly to complete, meaning it is only tab completed when invoked exactly as it was registered. ~The above line will not allow you to~ This method does not allow you to register the script by it's path, hence you cannot complete ./my-awesome-script.py, or /path/to/my-awesome-script.py.

would have been clearer. I am however not very good in English.

evanunderscore commented 7 years ago

It does allow you to register the path of a script if you want to, but then that's the only thing you'll be able to complete. eval "$(register-python-argcomplete /path/to/my-awesome-script.py)" would allow you to complete exactly /path/to/my-awesome-script.py and nothing else.

evanunderscore commented 7 years ago

@DerWeh I've made an attempt at rewording this to reduce confusion. I also removed the .py extensions from the examples to more strongly indicate what I think the intended usage is. Can you take a look at this and see if it makes more sense to you?

kislyuk commented 7 years ago

@DerWeh, I've merged the PR but please comment so we can continue to improve the docs.

DerWeh commented 7 years ago

@evanunderscore I think it is rather clear now. Of course I now already know what it is supposed to mean, so it is rather difficult to judge.