zsh-users
 help / color / mirror / code / Atom feed
* Re: 'whence' question
  2014-11-05 18:33 'whence' question Ray Andrews
@ 2014-11-05 17:49 ` Oliver Kiddle
  2014-11-05 18:00   ` Peter Stephenson
  2014-11-05 19:15   ` Ray Andrews
  2014-11-05 17:50 ` Peter Stephenson
  1 sibling, 2 replies; 10+ messages in thread
From: Oliver Kiddle @ 2014-11-05 17:49 UTC (permalink / raw)
  To: Ray Andrews; +Cc: Zsh Users

Ray Andrews wrote:
> ... yet, although '/usr/local/bin/zsh' is found, all of the other files 
> found by
> 'whence -a zsh' above are missed. How is it that '/usr/local/bin/zsh' 
> matches
> 'zsh*' but '/bin/zsh' does not?

Because /bin/zsh is hidden by /usr/local/bin/zsh. The commands are in a
hash table and there is only the one entry for zsh.

Looking at the source, it seems that whence doesn't support both -a and
-m together though it doesn't produce an error.

I'd agree that this isn't ideal. Note that whence -m does show a zsh
alias in addition to /usr/local/bin/zsh if there is one.

Oliver


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: 'whence' question
  2014-11-05 18:33 'whence' question Ray Andrews
  2014-11-05 17:49 ` Oliver Kiddle
@ 2014-11-05 17:50 ` Peter Stephenson
  1 sibling, 0 replies; 10+ messages in thread
From: Peter Stephenson @ 2014-11-05 17:50 UTC (permalink / raw)
  To: Zsh Users

On Wed, 05 Nov 2014 10:33:10 -0800
Ray Andrews <rayandrews@eastlink.ca> wrote:
> This seems right, the '-a' switch doesn't take wildcards:
> 
> 
>       $ whence -a zsh
>     /usr/local/bin/zsh
>     /usr/bin/zsh
>     /bin/zsh
> 
> ... however the '-m' switch accepts wildcards:
> 
> 
>     $ whence -m "zsh*"
>     /usr/local/bin/zsh
>     /usr/local/bin/zsh-ok
>     /usr/local/bin/zsh-test1
>     /usr/local/bin/zsh-test2-orig-rebuild
>     /bin/zsh4
>     /bin/zsh5
> 
> ... yet, although '/usr/local/bin/zsh' is found, all of the other files 
> found by
> 'whence -a zsh' above are missed. How is it that '/usr/local/bin/zsh' 
> matches
> 'zsh*' but '/bin/zsh' does not?

It's telling you the first instance of each distinct command it finds.
To find all instances, you need to specify -a as well.

pws


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: 'whence' question
  2014-11-05 17:49 ` Oliver Kiddle
@ 2014-11-05 18:00   ` Peter Stephenson
  2014-11-06  4:43     ` Bart Schaefer
  2014-11-05 19:15   ` Ray Andrews
  1 sibling, 1 reply; 10+ messages in thread
From: Peter Stephenson @ 2014-11-05 18:00 UTC (permalink / raw)
  To: Oliver Kiddle, Zsh Users

On Wed, 05 Nov 2014 18:49:23 +0100
Oliver Kiddle <okiddle@yahoo.co.uk> wrote:
> Looking at the source, it seems that whence doesn't support both -a and
> -m together though it doesn't produce an error.

You're right: I think *that's* a bug.

pws


^ permalink raw reply	[flat|nested] 10+ messages in thread

* 'whence' question
@ 2014-11-05 18:33 Ray Andrews
  2014-11-05 17:49 ` Oliver Kiddle
  2014-11-05 17:50 ` Peter Stephenson
  0 siblings, 2 replies; 10+ messages in thread
From: Ray Andrews @ 2014-11-05 18:33 UTC (permalink / raw)
  To: Zsh Users

[-- Attachment #1: Type: text/plain, Size: 551 bytes --]

This seems right, the '-a' switch doesn't take wildcards:


      $ whence -a zsh
    /usr/local/bin/zsh
    /usr/bin/zsh
    /bin/zsh

... however the '-m' switch accepts wildcards:


    $ whence -m "zsh*"
    /usr/local/bin/zsh
    /usr/local/bin/zsh-ok
    /usr/local/bin/zsh-test1
    /usr/local/bin/zsh-test2-orig-rebuild
    /bin/zsh4
    /bin/zsh5

... yet, although '/usr/local/bin/zsh' is found, all of the other files 
found by
'whence -a zsh' above are missed. How is it that '/usr/local/bin/zsh' 
matches
'zsh*' but '/bin/zsh' does not?


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: 'whence' question
  2014-11-05 17:49 ` Oliver Kiddle
  2014-11-05 18:00   ` Peter Stephenson
@ 2014-11-05 19:15   ` Ray Andrews
  1 sibling, 0 replies; 10+ messages in thread
From: Ray Andrews @ 2014-11-05 19:15 UTC (permalink / raw)
  To: Oliver Kiddle; +Cc: Zsh Users

On 11/05/2014 09:49 AM, Oliver Kiddle wrote:
> Ray Andrews wrote:
>> ... yet, although '/usr/local/bin/zsh' is found, all of the other files
>> found by
>> 'whence -a zsh' above are missed. How is it that '/usr/local/bin/zsh'
>> matches
>> 'zsh*' but '/bin/zsh' does not?
> Because /bin/zsh is hidden by /usr/local/bin/zsh. The commands are in a
> hash table and there is only the one entry for zsh.
>
> Looking at the source, it seems that whence doesn't support both -a and
> -m together though it doesn't produce an error.
You anticipate me.  '-am' was the first 'cure' I tried.
> I'd agree that this isn't ideal. Note that whence -m does show a zsh
> alias in addition to /usr/local/bin/zsh if there is one.
I'm not sure what the intuitive answer might be.  As Peter said, '-m' 
finds only the first *active*
match, whereas '-a' pointedly keeps looking. Perhaps '-a' might accept 
wildcards? That would
leave '-m' alone, but expand the usefulness of '-a' without (I hope) 
breaking anything.



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: 'whence' question
  2014-11-05 18:00   ` Peter Stephenson
@ 2014-11-06  4:43     ` Bart Schaefer
  2014-11-06 21:45       ` Ray Andrews
  0 siblings, 1 reply; 10+ messages in thread
From: Bart Schaefer @ 2014-11-06  4:43 UTC (permalink / raw)
  To: Zsh Users

On Nov 5,  6:00pm, Peter Stephenson wrote:
} Subject: Re: 'whence' question
}
} On Wed, 05 Nov 2014 18:49:23 +0100
} Oliver Kiddle <okiddle@yahoo.co.uk> wrote:
} > Looking at the source, it seems that whence doesn't support both -a and
} > -m together though it doesn't produce an error.
} 
} You're right: I think *that's* a bug.

Hmm.  This is more complicated than it at first appears.

The -a option is O(n*c) where n is $#path and c is $#argv, because it
merely has to glue the two arrays together and test whether each of
the resulting strings is an executable file path.  (I discount the
cost of one hash lookup for each hash table.)

The -m option currently is O(h*c) where h is the size of all the hash
tables, plus (one time only) the cost of filling the command table if
it hasn't already been.

To do "whence -am" the "right way" would also be approximately O(h*c)
because we have to compare every file in every directory in $path to
the list of patterns (and h is a fair estimate of that number of
files).  However, I'm not sure what the "right way" *is*, because:

The pattern accepted by the -m option is not a glob, it's a pattern of
the string-matching variety.  If we were to simply glue each of the
arguments onto the end of each $path directory and glob the resulting
cross-product, the wrong results could be returned.  Furthermore, for
e.g. cygwin, the filled hash table has dealt with mapping "foo.exe"
onto "foo" with the suffix case-insensitive, so even a string match
against the file names across $path could be wrong.

Having just written that, it occurs to me that perhaps the "right way"
is the equivalent of this? --

	whence -a ${(k)commands[(I)pattern]}


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: 'whence' question
  2014-11-06  4:43     ` Bart Schaefer
@ 2014-11-06 21:45       ` Ray Andrews
  2014-11-06 21:53         ` Bart Schaefer
  0 siblings, 1 reply; 10+ messages in thread
From: Ray Andrews @ 2014-11-06 21:45 UTC (permalink / raw)
  To: zsh-users

On 11/05/2014 08:43 PM, Bart Schaefer wrote:
> The pattern accepted by the -m option is not a glob,

That seems very counterintuitive!  I'm taking it as a regular glob just 
as, I think,
anyone would.
> it's a pattern of
> the string-matching variety.  If we were to simply glue each of the
> arguments onto the end of each $path directory and glob the resulting
> cross-product, the wrong results could be returned.  Furthermore, for
> e.g. cygwin, the filled hash table has dealt with mapping "foo.exe"
> onto "foo" with the suffix case-insensitive, so even a string match
> against the file names across $path could be wrong.
>
> Having just written that, it occurs to me that perhaps the "right way"
> is the equivalent of this? --
>
> 	whence -a ${(k)commands[(I)pattern]}
I couldn't get any love from that.  What I do in my wrapper is this:

     echo -e "\n\e[31;1mACTIVE:\n\e[0m`whence -mv "$1"`"
     echo -e "\n\e[31;1mSHADOWED AND/OR LINKS:\
                   \n\e[0m`whence -sav "${1//'*'/}"`"



> $ i zsh* << (i)nformation = mostly from whence.

> ACTIVE:
> zsh is /usr/local/bin/zsh
> zsh-ok is /usr/local/bin/zsh-ok
> zsh-test1 is /usr/local/bin/zsh-test1
> zsh-test2-orig-rebuild is /usr/local/bin/zsh-test2-orig-rebuild
>
> SHADOWED AND/OR LINKS:
> zsh is /usr/local/bin/zsh -> /usr/local/bin/zsh-test2-orig-rebuild
> zsh is /usr/bin/zsh -> /usr/local/bin/zsh-test2-orig-rebuild
> zsh is /bin/zsh -> /usr/local/bin/zsh-test2-orig-rebuild
>
... which is a bit clumsy, but if I type ' i zsh* ' I want 'whence-ish' 
information on
the intuitive meaning of 'zsh*' and I want to see links, and 'shadowed' 
files
because they may very well be part of a chain of links, as is true 
above. But '-m'
won't permit '-s', and '-a' won't permit glob.  I hope that something more
friendly can be come up with. I hope it's " whence -as "zsh*" "


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: 'whence' question
  2014-11-06 21:45       ` Ray Andrews
@ 2014-11-06 21:53         ` Bart Schaefer
  2014-11-06 23:15           ` Ray Andrews
  0 siblings, 1 reply; 10+ messages in thread
From: Bart Schaefer @ 2014-11-06 21:53 UTC (permalink / raw)
  To: Zsh Users

[-- Attachment #1: Type: text/plain, Size: 1420 bytes --]

On Thu, Nov 6, 2014 at 1:45 PM, Ray Andrews <rayandrews@eastlink.ca> wrote:

> On 11/05/2014 08:43 PM, Bart Schaefer wrote:
>
>> The pattern accepted by the -m option is not a glob,
>>
>
> That seems very counterintuitive!  I'm taking it as a regular glob just
> as, I think,
> anyone would.
>

A "regular glob" and a pattern aren't significantly different, but for
example you can't use (most) glob qualifiers in a pattern, and the meaning
of "/" is very different.  Note that "whence" is not a file search tool;
scanning a hash table of alias names with a glob comparing file type or
modification time would make no sense.

Having just written that, it occurs to me that perhaps the "right way"
>> is the equivalent of this? --
>>
>>         whence -a ${(k)commands[(I)pattern]}
>>
> I couldn't get any love from that.


Interesting, it worked very nicely for me even as far back as zsh-4.2.6 on
an ancient virtual machine:

% whence -vsa ${(k)commands[(I)zsh*]}
zshenv not found
zsh is an alias for zsh-4.2.6
zsh is /usr/local/bin/zsh -> /bin/zsh
zsh is /bin/zsh
zsh.old is /bin/zsh.old
zshrc not found
zsh-4.2.0 is /bin/zsh-4.2.0
zsh-4.2.3 is /bin/zsh-4.2.3
zsh-4.2.5 is /bin/zsh-4.2.5
zsh-4.2.6 is /bin/zsh-4.2.6

That should find all the names in the command hash table that begin with
zsh, and then pass them all to whence to find the full paths.  I'm not sure
why zshrc and zshenv are in the command hash table.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: 'whence' question
  2014-11-06 23:15           ` Ray Andrews
@ 2014-11-06 22:54             ` Bart Schaefer
  0 siblings, 0 replies; 10+ messages in thread
From: Bart Schaefer @ 2014-11-06 22:54 UTC (permalink / raw)
  To: Zsh Users

[-- Attachment #1: Type: text/plain, Size: 453 bytes --]

On Nov 6, 2014 2:43 PM, "Ray Andrews" <rayandrews@eastlink.ca> wrote:
>
> On 11/06/2014 01:53 PM, Bart Schaefer wrote:
>>
>> % whence -vsa ${(k)commands[(I)zsh*]}
>
> Ooops, I thought I had to replace 'commands' with (in this case) 'zsh*'.
> ... works fine Bart. (But really, shouldn't it be a bit simpler?).

Yes, probably.  I'm just using that as an example to nail down the desired
behavior of "whence -am ..." (and as a workaround in the meantime).

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: 'whence' question
  2014-11-06 21:53         ` Bart Schaefer
@ 2014-11-06 23:15           ` Ray Andrews
  2014-11-06 22:54             ` Bart Schaefer
  0 siblings, 1 reply; 10+ messages in thread
From: Ray Andrews @ 2014-11-06 23:15 UTC (permalink / raw)
  To: zsh-users

[-- Attachment #1: Type: text/plain, Size: 1114 bytes --]

On 11/06/2014 01:53 PM, Bart Schaefer wrote:
>
> A "regular glob" and a pattern aren't significantly different, but for
> example you can't use (most) glob qualifiers in a pattern, and the meaning
> of "/" is very different.  Note that "whence" is not a file search tool;
> scanning a hash table of alias names with a glob comparing file type or
> modification time would make no sense.
Quite so.  I'm limiting my thinking to files.
>
> Interesting, it worked very nicely for me even as far back as zsh-4.2.6 on
> an ancient virtual machine:
>
> % whence -vsa ${(k)commands[(I)zsh*]}
Ooops, I thought I had to replace 'commands' with (in this case) 'zsh*'.
... works fine Bart. (But really, shouldn't it be a bit simpler?).

    $ whence -vsa ${(k)commands[(I)zsh*]}

    zsh is /usr/local/bin/zsh -> /usr/local/bin/zsh-test2-orig-rebuild
    zsh is /usr/bin/zsh -> /usr/local/bin/zsh-test2-orig-rebuild
    zsh is /bin/zsh -> /usr/local/bin/zsh-test2-orig-rebuild
    zsh-ok is /usr/local/bin/zsh-ok
    zsh-test1 is /usr/local/bin/zsh-test1
    zsh-test2-orig-rebuild is /usr/local/bin/zsh-test2-orig-rebuild




^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2014-11-06 22:54 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-11-05 18:33 'whence' question Ray Andrews
2014-11-05 17:49 ` Oliver Kiddle
2014-11-05 18:00   ` Peter Stephenson
2014-11-06  4:43     ` Bart Schaefer
2014-11-06 21:45       ` Ray Andrews
2014-11-06 21:53         ` Bart Schaefer
2014-11-06 23:15           ` Ray Andrews
2014-11-06 22:54             ` Bart Schaefer
2014-11-05 19:15   ` Ray Andrews
2014-11-05 17:50 ` Peter Stephenson

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).