Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: disable substring match on command name
- X-seq: zsh-users 18549
- From: Amm <ammdispose-zsh@xxxxxxxxx>
- To: "zsh-users@xxxxxxx" <zsh-users@xxxxxxx>
- Subject: Re: disable substring match on command name
- Date: Mon, 3 Mar 2014 15:13:17 +0800 (SGT)
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1393830797; bh=9v9PV0pbiMkmCD3nK1USpemrTtV3fGhHka5MWPz8kIk=; h=X-YMail-OSG:Received:X-Rocket-MIMEInfo:X-Mailer:References:Message-ID:Date:From:Reply-To:Subject:To:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=fLiizLodzze+kv+bmq0KhbftXCKVR+3t2eJbWFYrhnCnzdP+gBOkxteUPnE+1mp3cLXIdPUrxG4kKGN5qojY9hdoQu2mfzrXRU04+rFxDGq+wa6dlnF62i5NEjt8UIX3uIoHjxvUwtt3BDQ38MxWF1/POIuZt48oPAEQzts+ARs=
- Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=X-YMail-OSG:Received:X-Rocket-MIMEInfo:X-Mailer:References:Message-ID:Date:From:Reply-To:Subject:To:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=SioTjIjQlRkApXZi1YwpjZtqBkxDYhE1MlZr49YtRvQEF1hDjhx4k8fnYpqceQKSBrJoO3iaQw7tO2qmbUGcjPYl+RoewK5HlIGhWOr1WHLMCLGtFeRlx/X8ZLcXpZl3Il/lCm0IkXJ2IEzbHb6rkCLj9kpQX9QXp65lFoOTOxM=;
- In-reply-to: <140302121855.ZM1118@torch.brasslantern.com>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <1393780084.43996.YahooMailNeo@web194601.mail.sg3.yahoo.com> <140302121855.ZM1118@torch.brasslantern.com>
- Reply-to: Amm <ammdispose-zsh@xxxxxxxxx>
> On Mar 3, Bart Schaefer wrote:
>> On Mar 3, 1:08am, Amm wrote:
>> zstyle ':completion:*' matcher-list '' 'r:|[._-]=** r:|=**' 'l:|=* r:|=*'
>>
>> This can cause accidental running of some different command if there is
>> spelling mistake.
>>
>> What I would like is substring match to work only on file and
>> directory names. (i.e. arguments to command)
(Snippets Bart Schaefer solution:)
> first we modify your matcher-list context like so:
> zstyle 'word-*:completion:*' matcher-list \
> '' 'r:|[._-]=** r:|=**' 'l:|=* r:|=*'
> Then we introduce a new matcher for word-1, which will be preferred to
> zstyle 'word-1:completion:*' matcher-list ''
> Finally we tweak the style that compsys is actually going to look up,
> zstyle -e ':completion:*' matcher-list \
> 'zstyle -a "word-${CURRENT}:completion:$curcontext" matcher-list reply'
Hi,
Thanks a lot for putting a lot of effort here. I appreciate it.
But your solution possible would not work if command is entered
after pipe symbol.
echo 1 2 | sort
In that example sort would NOT be the first word but 4th or 5th.
I have not tried your solution though. And I also find it little
bit hackish.
However I found a better solution after a lot of reading
(this is just my 2nd day learning zsh, so took lots of time)
TIP: I got hint from man page for zstyle tag-order
I removed matcher-list line. And added the following:
zstyle ':completion:*' tag-order '*' '*:-afrr' '*:-aflr'
zstyle ':completion:*:all-files-afrr' matcher 'r:|[._-]=** r:|=**'
zstyle ':completion:*:all-files-aflr' matcher 'l:|=* r:|=*'
First line tells to first run 'normal' tag-order. If a match
is not found run same tags but with -afrr appended to tag and
if match is still not found then run same with -aflr appended.
If zsh is expecting a command then all-files tag does not exist.
Hence matcher style is also not executed. (only normal match is
tried). So it will work even if command is like (echo 1 2 | sort).
zsh knows that after pipe it should be a command.
If zsh is expecting a filename then first it will try normal
match, if no match is found afrr and aflr (tag) matcher.
Hope this helps others who are looking for similar solutions.
(TIP: when zsh is expecting a directory [if its 'cd' command],
all-files tag is not checked. In that case you can use
local-directories tag in same way as all-files tag as above)
Amm
Messages sorted by:
Reverse Date,
Date,
Thread,
Author