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

Re: starting completions with =,<,>



chris s wrote:
> Ok, I was looking more into this, and it turns out the bash completion is
> able to handle =, >=,<=. The bash person did this:

That sort of approach wouldn't work in zsh. It does a lot of the work
for you when it comes to quoting.

In the previous e-mail:
> emerge -p =zsh-4.2.0-r1
> emerge -p '>zsh-4.2.0'
> emerge -p '<zsh-4.2.0'
> emerge -p '>=zsh-4.2.0'
> emerge -p zsh
> 
> are all valid commands. I saw in the manpage that _values does not
> support the equal sign. Unfortunately, that's exactly what I need.

I looked at your script and it is using _arguments. It's a bit messy to
handle the quoting. Try the following as a starting point:

  _arguments -C \
    '--pretend[pretend an emerge]' \
    '--exact[specify exact version]' \
    '*: :->args'

  case $state in
    args)
      if compset -P '(\\|)[<=>]*'; then
	compadd zsh-4.2.0-r1 etc etc
      else
	_values -S '' 'version prefix' \
	  '=[specify exact version]:' \
	  '<[specify maximum version]:' \
	  '>[specify too old version]:' \
	  '>=[specify minimum version]:'
	compadd zsh etc etc
      fi
    ;;
  esac

You'll need to put a proper tags loop around the bit with _values and
the other compadd. I'm not really using _values in the way it was
intended but this does work.

Note that you probably shouldn't be using the :*: stuff in _arguments.
Look inside the opt_args associative array from inside the args state
instead.

You don't need to do anything with the -equals- context. You just need
to either write:
  emerge -p \=zsh-4.2.0-r1   (or emerge -p '=zsh-4.2.0-r1')
or use unsetopt equals in your setup. This applies regardless of any
completion function setup. This is what the emerge man page means when
it says "in many shells you will need to escape characters such as '<'
and '='"

Oliver



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