From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23536 invoked by alias); 15 May 2014 09:15:25 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 18812 Received: (qmail 5088 invoked from network); 15 May 2014 09:15:10 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= daniel.shahaf.name; h=date:from:to:cc:subject:message-id :references:mime-version:content-type:in-reply-to; s=mesmtp; bh= U1blqNdTKVJJLCfrvwu+wNx2QCI=; b=VN6bDjOOuo8gscI5dv0Xqg69fQca6Jvp DbwsylDuqzniuIdXbidkekrgcyDc8CBjHVV/mX4S/eKzu1MfnRMg1+8JtC3km2KZ /sDKCSeVWM7eyDgS8uhBciYRF7FK2pVZJ4Q6eDpY92kg7F9WPQSmP0rzYeMFINft LJOvh92CnPM= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=date:from:to:cc:subject:message-id :references:mime-version:content-type:in-reply-to; s=smtpout; bh=U1blqNdTKVJJLCfrvwu+wNx2QCI=; b=UHRhD9L4/GbZj9oVKG35ScKUTbwV CZPwlIZOhjRgCvkWuZlzeqlYli+VHsjx8d5X4JpOW9keGI4cWZXMTZeVIiyBoldZ IYuIeLfQwUG6HwjsVmW1YCt8yoN8ewTWQ0pROQzdiZ4hEtTGARUlKrfg9o7T4+nK b4cdfUgVjOpzPH8= X-Sasl-enc: vHpcOU+C7u23QbHPs09A8+bh2ICHwfXUhnhvR8b4kIDy 1400145303 Date: Thu, 15 May 2014 09:14:58 +0000 From: Daniel Shahaf To: Roman Neuhauser Cc: Bart Schaefer , zsh-users@zsh.org Subject: Re: globbing in conditional expressions Message-ID: <20140515091458.GB2174@tarsus.local2> References: <20140507124101.GA53652@isis.sigpipe.cz> <20140507154407.660eb500@pwslap01u.europe.root.pri> <20140508105522.GE2052@tarsus.local2> <20140508122045.3c68c3fa@pwslap01u.europe.root.pri> <140508083418.ZM14713@torch.brasslantern.com> <20140508201936.GB53652@isis.sigpipe.cz> <140513084117.ZM22925@torch.brasslantern.com> <20140514041908.GF2471@tarsus.local2> <20140514210923.GF1629@isis.sigpipe.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20140514210923.GF1629@isis.sigpipe.cz> User-Agent: Mutt/1.5.21 (2010-09-15) Roman Neuhauser wrote on Wed, May 14, 2014 at 23:09:23 +0200: > # d.s@daniel.shahaf.name / 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.