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

Re: Can $PATH look into sub-folders?

On Wed, Aug 25, 2021 at 7:17 AM TJ Luoma <luomat@xxxxxxxxx> 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.

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