Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: globbing in conditional expressions
Roman Neuhauser wrote on Wed, May 14, 2014 at 23:09:23 +0200:
> # d.s@xxxxxxxxxxxxxxxxxx / 2014-05-14 04:19:08 +0000:
> > Bart Schaefer wrote on Tue, May 13, 2014 at 08:41:17 -0700:
> > > On May 8, 10:19pm, Roman Neuhauser wrote:
> > > }
> > > } maybe a crazy idea... how about something like [[ -m pattern ]] which
> > > } would succeed iff pattern matched at least one path? this could be
> > > } somewhat more amenable to shortcircuiting.
> > >
> > > Returning to this after a bit of a detour through [[ ... ]] expression
> > > parsing:
> > >
> > > You could define (via zmodload) an operator that applies filename
> > > generation to its argument, but changes to the internals of globbing
> > > would be needed to make a short-circuit happen. Then those changes
> > > would have to be exposed somehow so that the operator could use them.
> > >
> >
> > I've taken a shot at making those changes, see attached.
>
> wonderful, thank you!
>
You're welcome, but beware: the code doesn't work properly in all cases,
e.g., as Bart suspected, [[ -m **/*attr.yo(/) ]] (in a built zsh source
tree) false positives.
> i'm trying to think of a situation where [[ -m $pat ]] && mangle $REPLY
> would be useful for something other than foot-shooting... any ideas?
Well, there is:
while [[ -m $pat ]] ;
# Suppose -m implicitly sets $REPLY to a matching filename ...
() { mangle $1 && rm $1 } $REPLY
Since the filename returned would be the first in readdir() order, this
could result in starvation (some files never reaching mangle()) unless
the underlying filesystem's readdir() provides more guarantees than the
POSIX readdir() does.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author