zsh-workers
 help / color / mirror / code / Atom feed
From: Oliver Kiddle <okiddle@yahoo.co.uk>
To: Abhijeet Rastogi <abhijeet.1989@gmail.com>
Cc: zsh-workers@zsh.org
Subject: Re: String partial match from both left and right.
Date: Fri, 31 Aug 2018 13:11:08 +0200	[thread overview]
Message-ID: <23890-1535713868.126845@ueVC.nT4d.iPhW> (raw)
In-Reply-To: <CACXxYfxO8Ws4+Tf-NqSZW9b7gP7opRiEY5Dtpm7ZABG1K0N6Lg@mail.gmail.com>

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


  parent reply	other threads:[~2018-08-31 11:21 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20180831102508epcas4p4e1fdd60db2ae6336248268c887908f23@epcas4p4.samsung.com>
2018-08-31 10:24 ` Abhijeet Rastogi
2018-08-31 11:01   ` Peter Stephenson
2018-08-31 11:11   ` Oliver Kiddle [this message]
2018-09-02  4:37     ` Abhijeet Rastogi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=23890-1535713868.126845@ueVC.nT4d.iPhW \
    --to=okiddle@yahoo.co.uk \
    --cc=abhijeet.1989@gmail.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).