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

Re: dynamic reset of completion widget



On Thu, 4 Nov 2004, Francisco Borges wrote:

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

Seems to me the right way to do this would be to define _first to spot 
previously-unknown python scripts and hook them up.  Calling _first is 
already supported in the completion system, but the default implementation 
is a no-op.

E.g.

_first() {
  local command=$words[1]
  if (( CURRENT > 1 )) && [[ -z $_comps[$command] ]]; then
    if [[ $command = *.py ]]; then
      eval "$($command --make-zsh-widget)"
      compdef _$command $command
    fi
  fi
}



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