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

Re: String partial match from both left and right.



Abhijeet Rastogi wrote:
> function _hello {
>     _values -s ' ' 'dashboards' foo bar foo-bar
> }
> compdef _hello hello
>
> And what I want is, if I do:-
>
> $hello bar<TAB>
>
> I want `foo-bar` to come in the completion menu. I figured that it has
> something to do with mater-list but I can't seem to get it working.

You're right that the matching control is the way to achieve this and in
particular the 'l:|=*' specification.

> zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}' 'l:|=* r:|=*'

That sets a global matcher to apply for all completions. It will first
try case-insensitive matching and then try again with extra characters
allowed at both the beginning (left) and end (right) of what has been
typed. When you complete bar<tab>, the "bar" candidate will match when
doing the initial case-insensitive match and is accepted. It then never
gets to try the second matching rule.

You need the l: spec in the first argument so it would work with either:
  zstyle ':completion:*' matcher-list 'l:|=*'
or:
  zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z} l:|=* r:|=*'

That assumes you don't have any other matcher-list styles with a more
specific context.

Also, as I mentioned setting matcher-list is a fairly global setting. If
you only want this for hello then the matcher style might be more
appropriate:
  zstyle ':completion:*:hello:values:*' matcher 'l:|=*'

Alternatively you might want to specify the matcher directly in the
_hello function. For example:

  function _hello {
    _wanted dashboards expl 'dashboard' compadd -M 'l:|=*' foo bar foo-bar
  }

There are other things you might try, for example r:|-=* allows f-b to
match foo-bar.

Oliver



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