Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><a href="http://www.caliban.org/bash/#completion" rel="nofollow noreferrer">Bash "completion"</a> really is great. And easy for programs written in Python....</p> <p>I think this is just what you want: <a href="http://furius.ca/optcomplete/" rel="nofollow noreferrer">optcomplete: Shell Completion Self-Generator for Python</a>. It is available, e.g., as the "python-optcomplete" package in Ubuntu.</p> <p>You insert a few lines in your python program, and the user (one time) runs the bash "complete" program to tell bash how to complete the arguments:</p> <pre><code>complete -F _optcomplete &lt;program&gt; </code></pre> <p>and now the user has completion! By default it gives simple completion on program options. See the example for how to customize how completion works for a particular option. It is beautifully written, and easy to extend to handle sub-commands, alternate completion options, etc.!</p> <p><strong>Update:</strong></p> <p>For completion in zsh (for both optparse and argparse) see <a href="http://pypi.python.org/pypi/genzshcomp" rel="nofollow noreferrer">genzshcomp 0.3.1 : Python Package Index</a></p> <p>As noted by @englebip, we still need something similar for the new <code>argparse</code> module, introduced in Python 2.7 and 3.2, since <code>optparse</code> is now deprecated.</p> <p>Here is the discussion on moving in that direction:</p> <ul> <li><a href="http://www.gossamer-threads.com/lists/python/bugs/969495?do=post_view_threaded" rel="nofollow noreferrer">Mailing List Archive: [issue14103] argparse: add ability to create a bash_completion script</a></li> <li><a href="http://code.google.com/p/argparse/issues/detail?id=55" rel="nofollow noreferrer">Issue 55 - argparse - add a utilities for shell autocompleters to hook into as well as support for extending completion info - Python command line parsing - Google Project Hosting</a></li> </ul> <p>See also this background on how it is done: <a href="https://stackoverflow.com/questions/9568611/how-does-argparse-and-the-deprecated-optparse-respond-to-tab-keypress-after">How does argparse (and the deprecated optparse) respond to 'tab' keypress after python program name, in bash? - Stack Overflow</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload