zsh-users
 help / color / mirror / code / Atom feed
* Can $PATH look into sub-folders?
@ 2021-08-25 14:17 TJ Luoma
  2021-08-25 14:51 ` Peter Stephenson
  2021-08-25 14:57 ` Bart Schaefer
  0 siblings, 2 replies; 6+ messages in thread
From: TJ Luoma @ 2021-08-25 14:17 UTC (permalink / raw)
  To: Zsh MailingList

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

It is my understanding the zsh (and others) do not usually look into
sub-folders of $PATH for commands.

For example, if /usr/local/bin/ is in my $PATH and I have a folder
/usr/local/bin/private/ then zsh would not ‘see’ any scripts/utilities/etc
that were in /usr/local/bin/private/ unless I specifically added
/usr/local/bin/private/ to my $PATH.

That seems to be my experience, at least.

My question is whether or not there is an option (a zsh-specific option is
fine) which would tell zsh to include sub-folders of $PATH folders without
having to explicitly add them all to $PATH.

As always, thanks for your help,

~ Tj

[-- Attachment #2: Type: text/html, Size: 964 bytes --]

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

* Re: Can $PATH look into sub-folders?
  2021-08-25 14:17 Can $PATH look into sub-folders? TJ Luoma
@ 2021-08-25 14:51 ` Peter Stephenson
  2021-08-25 15:36   ` TJ Luoma
  2021-08-30 14:20   ` zzapper
  2021-08-25 14:57 ` Bart Schaefer
  1 sibling, 2 replies; 6+ messages in thread
From: Peter Stephenson @ 2021-08-25 14:51 UTC (permalink / raw)
  To: Zsh MailingList

> On 25 August 2021 at 15:17 TJ Luoma <luomat@gmail.com> wrote:
> It is my understanding the zsh (and others) do not usually look into
> sub-folders of $PATH for commands.
> 
> For example, if /usr/local/bin/ is in my $PATH and I have a folder
> /usr/local/bin/private/ then zsh would not ‘see’ any scripts/utilities/etc
> that were in /usr/local/bin/private/ unless I specifically added
> /usr/local/bin/private/ to my $PATH.
> 
> That seems to be my experience, at least.
> 
> My question is whether or not there is an option (a zsh-specific option is
> fine) which would tell zsh to include sub-folders of $PATH folders without
> having to explicitly add them all to $PATH.

The only choices I can see are:

Firstly, set the PATH_DIRS option and refer to them by relative path, i.e.
private/...

Secondly, use recursive globbing to add the directories to path, so at
least you don't need to do that explicitly.  In other words,

path+=(/usr/local/bin/**/*(/))

pws


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

* Re: Can $PATH look into sub-folders?
  2021-08-25 14:17 Can $PATH look into sub-folders? TJ Luoma
  2021-08-25 14:51 ` Peter Stephenson
@ 2021-08-25 14:57 ` Bart Schaefer
  1 sibling, 0 replies; 6+ messages in thread
From: Bart Schaefer @ 2021-08-25 14:57 UTC (permalink / raw)
  To: TJ Luoma; +Cc: Zsh MailingList

On Wed, Aug 25, 2021 at 7:17 AM TJ Luoma <luomat@gmail.com> wrote:
>
> My question is whether or not there is an option (a zsh-specific option is fine) which would tell zsh to include sub-folders of $PATH folders without having to explicitly add them all to $PATH.

Not directly, no.  There are a couple of ways to approach this that I
can think of:

Zero, the PATH_DIRS approach that PWS already mentioned.

One, if the subdirs contain shell scripts that can be run by zsh, you
can zcompile the entire tree into a bundled .zwc at a level that is in
the path, but that turns them into shell functions which may not be
the behavior you want.

Two, use a command_not_found_handler function to invoke a deeper
search if the initial search doesn't work.

Three, instead of explicitly adding directories to the path, add the
commands themselves with the "hash" builtin.

Four, combine two and three:  Locate the command with
command_not_found_handler, and then before running it, update a file
with the location.  In precmd, check for modification of that file,
and "hash" the newly-found command.


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

* Re: Can $PATH look into sub-folders?
  2021-08-25 14:51 ` Peter Stephenson
@ 2021-08-25 15:36   ` TJ Luoma
  2021-08-30 14:20   ` zzapper
  1 sibling, 0 replies; 6+ messages in thread
From: TJ Luoma @ 2021-08-25 15:36 UTC (permalink / raw)
  To: Zsh MailingList

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

On Aug 25, 2021 at 10:51:33 AM, Peter Stephenson <
p.w.stephenson@ntlworld.com> wrote:

Secondly, use recursive globbing to add the directories to path, so at
> least you don't need to do that explicitly.  In other words,
>
> path+=(/usr/local/bin/**/*(/))
>
>
Dang, that is both clever and smart. I think that will work perfectly.

At this point I only anticipate having one level of sub-folder, but who
knows? That might change in the future.

Thank you!

~ Tj

[-- Attachment #2: Type: text/html, Size: 1267 bytes --]

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

* Re: Can $PATH look into sub-folders?
  2021-08-25 14:51 ` Peter Stephenson
  2021-08-25 15:36   ` TJ Luoma
@ 2021-08-30 14:20   ` zzapper
  2021-08-30 15:32     ` Bart Schaefer
  1 sibling, 1 reply; 6+ messages in thread
From: zzapper @ 2021-08-30 14:20 UTC (permalink / raw)
  To: zsh-users


On 25/08/2021 15:51, Peter Stephenson wrote:
>> On 25 August 2021 at 15:17 TJ Luoma <luomat@gmail.com> wrote:
>> It is my understanding the zsh (and others) do not usually look into
>> sub-folders of $PATH for commands.
>>
>> Secondly, use recursive globbing to add the directories to path, so at
>> least you don't need to do that explicitly.  In other words,
>>
>> path+=(/usr/local/bin/**/*(/))
>>
>> pws
>>
I guess we can also have tilda exclusions?




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

* Re: Can $PATH look into sub-folders?
  2021-08-30 14:20   ` zzapper
@ 2021-08-30 15:32     ` Bart Schaefer
  0 siblings, 0 replies; 6+ messages in thread
From: Bart Schaefer @ 2021-08-30 15:32 UTC (permalink / raw)
  To: zzapper; +Cc: Zsh Users

On Mon, Aug 30, 2021 at 7:21 AM zzapper <zsh@rayninfo.co.uk> wrote:
>
> >> path+=(/usr/local/bin/**/*(/))
> >>
> I guess we can also have tilda exclusions?

It's just a glob like any other, so yes.


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

end of thread, other threads:[~2021-08-30 15:33 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-25 14:17 Can $PATH look into sub-folders? TJ Luoma
2021-08-25 14:51 ` Peter Stephenson
2021-08-25 15:36   ` TJ Luoma
2021-08-30 14:20   ` zzapper
2021-08-30 15:32     ` Bart Schaefer
2021-08-25 14:57 ` Bart Schaefer

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