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

Re: globbing in conditional expressions



# schaefer@xxxxxxxxxxxxxxxx / 2014-05-08 08:34:18 -0700:
> On May 8, 12:20pm, Peter Stephenson wrote:
> }
> } > All three solutions first set an array to the result of the glob.  Is
> } > there a solution that short-circuits, i.e., that returns as soon as a
> } > single matching filename is found?
> } 
> } No, unless someone remembers I feature I don't know about, because
> } internally the glob proceeds until it's finished
> 
> Well ... you can do this horrible hack:
> 
>   found=
>   # Stop after finding exactly one directory, for example:
>   : **/*(e+'[[ -d $REPLY ]] && { found=$REPLY ; kill -INT $$ }'+)
>   print $found
> 
> Of course to make this "useful" all the stuff that you'd test in the
> glob qualifiers you instead need to test in the [[ ... ]] before you
> assign found=$REPLY, probably by using the zsh/stat module; and you
> can't avoid scanning an unknown number of potential NON-matches up
> to the point where $found gets set, so in the worst case it's no
> better (and probably much worse) than just letting the glob finish.

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.

-- 
roman



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