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

Re: disable substring match on command name




> 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