From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14308 invoked by alias); 14 May 2014 21:09:40 -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: 18809 Received: (qmail 28545 invoked from network); 14 May 2014 21:09:26 -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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham version=3.3.2 Date: Wed, 14 May 2014 23:09:23 +0200 From: Roman Neuhauser To: Daniel Shahaf Cc: Bart Schaefer , zsh-users@zsh.org Subject: Re: globbing in conditional expressions Message-ID: <20140514210923.GF1629@isis.sigpipe.cz> 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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20140514041908.GF2471@tarsus.local2> User-Agent: Mutt/1.5.21 (2010-09-15) # 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! > > As I mentioned before, in the case of the match failing this would be > > exactly as expensive as not short-circuiting. > > Right, so short-circuiting would only be useful for callers that want to > know whether a pattern matches a large directory, but don't care about > having a list of matching filenames. Does anyone have such a use-case? s/a large directory// and you have exactly my use case: i only care about simple and succint code. (lack of) improved efficiency was Bart's concern. my original use case was along these lines: if ! is-mount $dst; then if ! is-empty $dst; then printf "%s: garbage in %s\n" $0 $dst return 1 fi run sudo mount --bind $src $dst fi where is-empty is now forced to function is-empty # {{{ { local -a d d=(${1:?}(N/F)) (( $#d == 0 )) } # }}} whereas i expected to be able to write sth like if ! is-mount $dst; then if [[ -m $dst/*(D) ]]; then or if ! is-mount $dst; then if [[ -m $dst(/F) ]]; then this piece of code deals with directories typically under 10 entries so i don't care about the performance impact of shortcircuting. if i cared about the matched filenames, the code would be structured differently and proably wouldn't call for a condexpr at all. i'm trying to think of a situation where [[ -m $pat ]] && mangle $REPLY would be useful for something other than foot-shooting... any ideas? -- roman