Free shell auto-completion #21

Open
dknecht opened this Issue Jun 17, 2012 · 6 comments

Comments

Projects
None yet
5 participants

dknecht commented Jun 17, 2012

No description provided.

Owner

keleshev commented Jun 18, 2012

Usually this requires modifying ~/.bashrc in order to work. And very few people do that even for such complex interfaces as git.

So, requiring high effort and having low impact, this is given low priority, unless someone implements that and makes a pull request.

Check out infi.docopt_completion. It generates shell auto-completion for a given docopt utility.

easy_install infi.docopt_completion
docopt-completion [script name]

The code is available here:
https://github.com/Infinidat/infi.docopt_completion/

Honghe commented Dec 10, 2013

@wiggin15 Test at docopt.__version__ = 0.6.1 but have problems, it does not work. at Ubuntu 12.04 32bit.
test the simple file docopt_example.py as follow:

 #!/usr/bin//env python
 # coding: utf-8

 """Usage:
     docopt_example.py tcp <host> <port> [--timeout=<seconds>]
     docopt_example.py serial <port> [--baud=9600] [--timeout=<seconds>]
     docopt_example.py -h | --help | --version

 """
 from docopt import docopt

 if __name__ == '__main__':
     arguments = docopt(__doc__, version='0.1.1rc')
     print arguments

The test command is:

sudo docopt-completion ./docopt_example.py  
Completion file written to /etc/bash_completion.d/docopt_example.py.sh

I think this means is OK, but still can not use tab-completion at ./docopt_example.py
So Which steps I was wrong?
Thanks!

You're right, looks like this happens because docopt-completion does not sanitize the "." in ".py". Please open an issue in the docopt-completion repository (link above) and I'll fix it. In the meantime you can change the name from docopt_example.py to docopt_example and see if that works.

Honghe commented Dec 10, 2013

Thanks! Cause notebook not at hand, will report it tomorrow morning.

Honghe at Android Gmail
On Dec 10, 2013 11:10 PM, "wiggin15" notifications@github.com wrote:

You're right, looks like this happens because docopt-completion does not
sanitize the "." in ".py". Please open an issue in the docopt-completion
repository (link above) and I'll fix it. In the meantime you can change the
name from docopt_example.py to docopt_example and see if that works.


Reply to this email directly or view it on GitHubhttps://github.com/docopt/docopt/issues/21#issuecomment-30234818
.

kbrock commented Mar 30, 2016

Taking a note from a crystal library completion, if you pass in the option --completion it generates the bash necessary to define an auto completion method.

But if you notice, for autocompletion to work best, the library (docopt in this case) would need some convention as to the data types of the values. Currently the variable name is mostly used. So this could be tricky.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment