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

Re: symlink chain.



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.



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