zsh-users
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-users@zsh.org
Subject: Re: symlink chain.
Date: Sun, 04 Jan 2015 17:34:48 -0800	[thread overview]
Message-ID: <150104173448.ZM19453@torch.brasslantern.com> (raw)
In-Reply-To: <54A9A76A.7020303@eastlink.ca>

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.


  reply	other threads:[~2015-01-05  1:35 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-27  4:50 Ray Andrews
2014-12-27 23:38 ` Ray Andrews
2015-01-02 17:03 ` Peter Stephenson
2015-01-02 18:42   ` Ray Andrews
2015-01-02 20:27     ` Lawrence Velázquez
2015-01-02 21:19       ` Ray Andrews
2015-01-02 21:24     ` Peter Stephenson
2015-01-02 21:36       ` Ray Andrews
2015-01-02 21:53       ` Ray Andrews
2015-01-02 22:21         ` Peter Stephenson
2015-01-02 23:42           ` Ray Andrews
2015-01-03  1:08             ` Ray Andrews
2015-01-03  5:03               ` Bart Schaefer
2015-01-03  5:53                 ` Ray Andrews
2015-01-03  7:17                   ` Bart Schaefer
2015-01-03 17:14                     ` Ray Andrews
2015-01-03 20:02                       ` Bart Schaefer
2015-01-03 21:13                         ` Ray Andrews
2015-01-03 21:42                           ` Peter Stephenson
2015-01-03 22:42                             ` Ray Andrews
2015-01-04  0:41                               ` Bart Schaefer
2015-01-04  3:45                                 ` Ray Andrews
2015-01-04  0:40                           ` Bart Schaefer
2015-01-04  3:35                             ` Ray Andrews
2015-01-04  8:31                               ` Bart Schaefer
2015-01-04 20:49                                 ` Ray Andrews
2015-01-05  1:34                                   ` Bart Schaefer [this message]
2015-01-05  2:28                                     ` Lawrence Velázquez
2015-01-05  4:24                                       ` Ray Andrews
2015-01-02 22:22         ` Bart Schaefer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=150104173448.ZM19453@torch.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).