Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

dynamic reset of completion widget

I hope the subject wasn't that confusing...

I want to automatically create zsh widgets for python programs using
python's standard option parser framework (optparse) and I want also to
be able to make and set this widget on-the-fly.

Here is the full story...

Yesterday I made a small script that, called from inside my foo.py
script, outputs a zsh completion widget to a file _foo.py.

This gives me a fast completion widget but it involves some shell
configuration every time I change options.


This guy has done a python module (http://furius.ca/optcomplete/) that
will provide bash directly with option completion through bash's
'completion protocol', e.g. setting COMP_(CWORD|LINE|POINT|WORDS) and

So appart from a stable _foo.py file, I think it would also be good to
have a on-the-fly completion widget for zsh, like the one done for

Wondering how to do it, I saw two possibilities:

1. Do the same as optcomplete does for bash, e.g. talk to the shell by
setting the correspondent variables;


(don't know if this is possible, but it seems easier) 
2. Have a default widget for my python script, say _optparse, that makes
a new custom widget and rebinds the completion of foo.py to _foo.py

# I start with
compdef _optparse foo.py 
compdef _optparse bozo.py

# I'm not a zsh programmer, so please have patience here...

# discover the name of the command we are completing
set bar=`give the command name I'm completing`

eval "`$bar --make-zsh-widget`"
# which would return something like:
# "_foo.py() { compadd Scooby Dooby Doo; }"

compdef _$bar $bar

Is this possible? Can I just rebind like this?

I imagine I'm not taking care of all details yet...

Any ideas, comments or suggestions? All welcome.

Any example of something similar? (I must confess that I find zsh
documentation a bit overwhelming...)


Messages sorted by: Reverse Date, Date, Thread, Author