From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15620 invoked by alias); 5 Jan 2015 01:35:17 -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: 19690 Received: (qmail 19442 invoked from network); 5 Jan 2015 01:35:03 -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,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 X-CMAE-Score: 0 X-CMAE-Analysis: v=2.1 cv=D9vw8UVm c=1 sm=1 tr=0 a=FT8er97JFeGWzr5TCOCO5w==:117 a=kj9zAlcOel0A:10 a=q2GGsy2AAAAA:8 a=oR5dmqMzAAAA:8 a=-9mUelKeXuEA:10 a=YNv0rlydsVwA:10 a=xXXHpwHoCisj6B-5VoYA:9 a=CjuIK1q_8ugA:10 From: Bart Schaefer Message-id: <150104173448.ZM19453@torch.brasslantern.com> Date: Sun, 04 Jan 2015 17:34:48 -0800 In-reply-to: <54A9A76A.7020303@eastlink.ca> Comments: In reply to Ray Andrews "Re: symlink chain." (Jan 4, 12:49pm) References: <549E3A7B.9010209@eastlink.ca> <20150102170307.7d2e644a@ntlworld.com> <54A6E6B1.6070201@eastlink.ca> <20150102212422.3a761af5@ntlworld.com> <54A7136C.1060102@eastlink.ca> <20150102222140.1303a633@ntlworld.com> <54A72CEF.9090102@eastlink.ca> <54A740F3.4040902@eastlink.ca> <150102210337.ZM22099@torch.brasslantern.com> <54A783C3.3000006@eastlink.ca> <150102231734.ZM22168@torch.brasslantern.com> <54A82374.1030208@eastlink.ca> <150103120252.ZM23074@torch.brasslantern.com> <54A85B6C.4020103@eastlink.ca> <150103164002.ZM23676@torch.brasslantern.com> <54A8B4EE.30908@eastlink.ca> <150104003130.ZM24261@torch.brasslantern.com> <54A9A76A.7020303@eastlink.ca> X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: zsh-users@zsh.org Subject: Re: symlink chain. MIME-version: 1.0 Content-type: text/plain; charset=us-ascii On Jan 4, 12:49pm, Ray Andrews wrote: } } But, would we not agree that it is the natural thing to prefer } cumulative switches over limiting switches? Is it not intuitive that } as you 'add' switches you 'add' features? There's no answer for this that fits all cases. In an ideal world, one would always think of the minimal action and then build on it, but the world is rarely ideal. More often there exists something that has a purpose or mechanism very similar to a new idea, and so that something is altered to support the new idea. A lot of times, that isn't an additive process. } And then we have the question of the 'smartness' of switches. 'ls -g': } group directories first. Imagine if the output was nothing if it } turned out that there *were* no directories to sort first. This is not a good example, because "ls -g" refers to sorting, whereas "whence -m" refers to searching. A better example would be "grep -f". Consider ls -l /usr/local/bin | grep '.*zsh.*' vs. ls -l /usr/local/bin | grep -f '.*zsh.*' Should the latter grep revert to pattern matching because the literal string failed to match anything? Did -f add a feature to grep? Did I sabotage the output when the second grep found nothing? (I'm going to return to this in a moment.) } < micro-rant> } I myself will never, ever use a slash for anything but what God meant it } to be used for and I think it is monstrous that anyone would think of } doing otherwise, nor should zsh even permit such blasphemy. } Apparently that means you're going to use a slash only to close your HTML tags ...? } > Switches often change the meaning of arguments. Look at the example } > we just went through with (print '\e') vs. (print -r '\e'). } } Good example. Still -r never 'invalidates' an argument. Imagine if -r } forced print to print nothing if there were no escapes for it to handle-- } is that not the symmetric comparison with -m? No, it's not symmetric, because print doesn't have any other job to do with the arguments, whereas whence does have another job (compare them to something). If you want symmetry, try "print %G" vs. "print -P %G". } whence: trynormalstearch || error } } whence -m: trypatternsearch || trynormalsearch || error } } Not to strange, is it? OK, now you've hit on something that actually might be a problem. To return to ls -l /usr/local/bin | grep -f '.*zsh.*' That would typically return nonzero because the grep failed to match anything. The trouble this illustrates is that whence -m /this/is/a/file/path and whence -a this_is_not_a_command both return zero. Other cases in which whence does not find anything return nonzero. So you can't successfully write whence -m $1 || whence -a $1 || whence $1 which would be the "normal" way to do what you want. I think whence should return a detectable failure when the pattern doesn't match, rather than just output nothing. } In the manual: " -M will attempt a pattern match, (as -m), but will } then attempt a normal match if the pattern match fails. This can be } either a normal argument, or a pattern argument." } } So IMHO the question becomes, would that add utility? I say it would. I could be convinced to agree with you except for two things: (1) A pattern like [a-z] or using # or ## with extendeglob matches a very different set of strings than does the literal '[a-z]' etc. You have to consider the case of a pattern getting a false hit when taken as a plain string, as well as the case of a plain string getting a "false" miss when taken as a pattern. (2) The set of things searched by whence is not limited to files, and this adds utility only for the case where the search is meant (by the user) to be restricted to files. This compounds the effects of (1). } (But Peter likes it for -a at least even if not for -m, [...]) The -a case avoids (1) entirely and does not affect the behavior of (2) for the non-file searches performed by whence.