optcomp - shell completion for optiek

Francisco Borges <[email protected]> Fri, 5 Nov 2004 17:54:29 +0100
Newsgroups gmane.comp.python.optik.user
Organization Alfa Informatica - Rijksuniversiteit Groningen
Message-ID <[email protected]>
Hello!

I've made a python module that, given a OptionParser object, produces a
completion widget for zsh and a 'complete' command for tcsh. The idea is
to include support for bash as well, but first I have to learn how to
write bash completion scripts ;-)

In the case of zsh, with the use of a shell script, you can have dynamic
generation of the widget (in bash this should also be feasible).

Everything is a bit rough on the edges [*] but "it works"=AE.=20

[*]: tcsh completion needs more work and options that take more than one
argument have not be dealt with yet.

Interested? Wait no more!!

Check it at http://loki.let.rug.nl/~borges/optcomp/optcomp.tar.gz, and pl=
ease
let me know if you have suggestions or comments on it.

Peace,
Francisco.

#------------------------------------------------------

Some details:

Here is how you use it:

# define some options
from optparse import OptionParser, OptionGroup
prs =3D OptionParser()
prs.add_option('--foo', help=3D'bla bla', dest=3D'foo')

import optcomp
optcomp.completion(prs, __file__)

(opt, args) =3D prs.parse_args()

Regarding python, that's it. Then you may use=20

> pyfoo --optcomp-write

which will make two files: _pyfoo (zsh) and pyfoo.tcsh.

Or if using (zsh) you may configure it to do this automatically on every
shell session.

For details on usage, check the module __doc__ string or the README file
that comes with it.

#-------------------------------------------------------------------

Differences with optcomplete

Optcomplete is a related module that does the same for Bash; the main
difference is that optcomp uses the shell machinery to perform
completion, while optcomplete tries to do everything within
python. IMHO, that seems a waste of the already existing shell
functions.

A consequence of that is that one can preconfigure the shell to use a
particular function or configure things on the fly.  In this last case,
differently from optcomplete, the generation of the widget is made only
once per shell session and not everytime you hit TAB.

If your home machine is a Pentium 500Mh, that does make a difference...=20


--=20
Francisco Borges
Alfa Informatica - RuG



-------------------------------------------------------
This SF.Net email is sponsored by:
Sybase ASE Linux Express Edition - download now for FREE
LinuxWorld Reader's Choice Award Winner for best database on Linux.
http://ads.osdn.com/?ad_id=5588&alloc_id=12065&op=click