Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

register-python-argcomplete - exactly registered name #213

Open
DerWeh opened this issue Mar 11, 2017 · 10 comments
Open

register-python-argcomplete - exactly registered name #213

DerWeh opened this issue Mar 11, 2017 · 10 comments

Comments

@DerWeh
Copy link

DerWeh commented Mar 11, 2017

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
Copy link
Collaborator

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
Copy link
Author

DerWeh commented Mar 15, 2017

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
Copy link
Collaborator

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
Copy link
Author

DerWeh commented Mar 15, 2017

@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
Copy link
Collaborator

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
Copy link
Author

DerWeh commented Mar 25, 2017

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
Copy link
Collaborator

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
Copy link
Collaborator

@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
Copy link
Owner

kislyuk commented Jun 4, 2017

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

@kislyuk kislyuk reopened this Jun 4, 2017
@DerWeh
Copy link
Author

DerWeh commented Jun 4, 2017

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants