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

Re: [patch] Add ldap completer



Matthew Martin wrote:
> For the protocol _describe, is -I correct? I don't grok the differences
> between the prefixes and suffixes. For host is -S '' correct for not
> adding a space after and should the completer avoid adding the space?

You should use -S.
The normal way would actually be to have:
  compset -S ':*' || suf=( -S :// )
Then append $suf to _describe.

-S/-P are what you normally use for separators like : / ,  etc.
These work together with the suffix auto-removal. The completion
matching is aware of them and considers them for some purposes.

-s/-p suffixes/prefixes are included in matching control. So if you use, e.g:
  compadd -M 'r:|/=* r:|=*' -p "head/" - tail
  then h/t</tab> will complete to head/tail
This is behind things like _multi_parts. They are also quoted
automatically whereas for -P/-S you might need compquote so these are
sometimes used to take advantage of that.

-i/-I is akin to directly modifying IPREFIX and ISUFFIX. They tend
to be used when bypassing matching but can have other uses. Aside
from quoting, they don't behave exactly like a direct modification of
IPREFIX/ISUFFIX but that goes beyond my understanding.

> The ldapi protocol is not completed correctly because I don't know how
> to make _files replace / with %2f.

I don't think you can currently without redoing much of _files. You
could probably still get _path_files (with -S %2f) to do much of the
work.
The completion system does track layers of quoting following compset -q
but you can't give it custom forms as %2f would be.

> +  # [protocol://]host[:port][/basedn[?[attribute,...][?[scope][?[filter]]]]]
> +  if ! compset -P '*://'; then
> +    tags=(protocol)
> +  fi
> +
> +  if ! compset -P '*/'; then
> +    if compset -P '*:'; then

In general, where you have compset -P. compset -S is also applicable
when completing whatever falls to the left of the separator.

> +  _tags $tags
> +  while _tags; do
> +    _requested protocol && _describe -t protocol protocol protocols -I ://
> +    _requested host && _hosts -S ''
> +    _requested port && _guard '|<1-65535>' port

_guard was created to solve a particular problem. A quick demonstration
of which is the following: _arguments '--long' ':number:'
  --l<tab> now does not complete to --long because number is being
offered.
I tend to limit it's use to these situations. Even if I've typed some
letters, getting the "port" description can still be useful.

> +    _requested basedn expl 'base DN'
> +    _requested attribute expl attribute
> +    _requested scope && _describe -t scope scope scopes

If the scope is followed by '?' and a filter, you might want a ? suffix
on this. Perhaps in auto-removable form. Or the default suffix could be
auto-removable.

> +    _requested filter expl filter
> +  done

The tags loop is not correct. You need to break out of the loop if
matches were added. _alternative would work here. $tags never contains
more than one value, however, so the easiest would just be to directly
generate matches in each place where you assign to $tags.

If you don't like adding && ret=0 everywhere, compare
compstate[nmatches] from the start and end of the function.

> +        ':: :_guard "*=*" "filter"' \

Is this really doing what you want: offering filter only if there is an
equals sign in the current word?

Oliver



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