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

Re: problem with context specification



Bart Schaefer wrote on Tue, 14 Jan 2020 18:34 +00:00:
> On Tue, Jan 14, 2020 at 10:06 AM Peter Stephenson
> <p.stephenson@xxxxxxxxxxx> wrote:
> >
> > On Tue, 2020-01-14 at 16:45 +0000, Daniel Shahaf wrote:
> > > > I assume the stars are for matching every possible value for that segment,
> > > No.  An asterisk matches zero or more characters, _including colons_.
> >
> > This can certainly be a right pain.
> 
> It's important to remember that the colons are strictly a completion
> system convention -- they have nothing to do with the semantics of
> zstyle itself,

That's not so.  A colon is hardcoded into the determination of which
pattern is more specific than another.  For example, consider this:

zstyle ':foo:*' key value
zstyle ':foo:bar:*' key value

This is two patterns.  The second one is more specific than the first
because it has more segments.  The order of definition of these two
patterns will not affect lookup results:

% zstyle ':foo:*' key value1 
% zstyle ':foo:bar:*' key value2 
% zstyle -s :foo:bar:baz key a 
% zstyle -d ':foo:*'
% zstyle -d ':foo:bar:*'
% zstyle ':foo:bar:*' key value2 
% zstyle ':foo:*' key value1 
% zstyle -s :foo:bar:baz key b 
% echo $a $b 
value2 value2
% 

Now, change the example to not use colons:

zstyle '/lorem/*' key value
zstyle '/lorem/ipsum/*' key value

This is two patterns that are *equally* specific — each of them consists
of one colon-separated segment that's neither a literal string nor the
pattern «*» — so the order of definition does matter: if you change the
order of definitions of these two patterns, lookup results will be
different:

% zstyle '/lorem/*' key value1 
% zstyle '/lorem/ipsum/*' key value2 
% zstyle -s /lorem/ipsum/dolor key a 
% zstyle -d '/lorem/*'
% zstyle -d '/lorem/ipsum/*'
% zstyle '/lorem/ipsum/*' key value2 
% zstyle '/lorem/*' key value1 
% zstyle -s /lorem/ipsum/dolor key b 
% echo $a $b 
value1 value2
% 

This is documented and tested.



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