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

Re: whence (was Re: local unfunction)

On Sat, Mar 31, 2018 at 10:21 AM, Ray Andrews <rayandrews@xxxxxxxxxxx> wrote:
> $ whence -wm "zsh*"
> zsh: command
> zsh5.3: command        # binary
> zsh5.3:: command        # text file

What's with the extra ":" there?  Is there actually a colon in the file name?

> ... I've yet to understand what the point of the '-w' switch is.

% zsh() { print nope }
% alias zsh='print not this either'
% whence -w zsh
zsh: alias
% whence -wa zsh
zsh: alias
zsh: function
zsh: command

> -a # keep looking after the first match (the one to be executed) is found

So far so good.

> -m # find all matches of a pattern, subsumes '-a'  (executable ONLY unless
> ... )

No, this does not subsume -a, because it will only return hits from
the internal hash tables.  Thus if you have a file named "zsh" in 3
different directories in $path, the command hash table will contain
only the first of those, and whence -m will find only that one.
However, if you have three differently-named files matching "zsh*" in
$path, they will all have separate entries in the command hash table,
and whence -m will list all three.

> -t # Show non executable (text?) files as well, obviates -a, subsumes 'm'.

This being a proposed new flag.  I think this points to the source of
the confusion.  The command hash table will contain the first
occurrence of every file name from every directory in $path, even if
that first occurrence is not executable, and "whence -m" will show you
all of the matching entries in the hash table.  The existing -m option
subsumes your -t.

The other confusion is that -m never searches $path.  It always
populates the command hash table if necessary and then searches the
hash table.

% path=(./Src $path)
% whence zsh
% whence -a zsh
% whence -m zsh

There's one magic side-effect of combining -a and -m, which is that -m
will find something in the hash table and then -a will search $path
for what was found.  That's a result of re-using the code that walks
the path to do the output formatting for the names found by -m.

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