On Thu, 16 May 2024 at 02:48, Koichi Murase <myoga.mur...@gmail.com> wrote:

> 2024年5月14日(火) 15:09 Martin D Kealey <mar...@kurahaupo.gen.nz>:
> > 1. I therefore propose that where a relative path appears in
> > BASH_SOURCE_PATH, it should be taken as relative to the directory
> > containing $0 (after resolving symlinks), rather than relative to $PWD.
>
> [...]
>
However, I think what is generally achieved by proposal 1 would be
>
>   source "$__dir__/<one of relpaths in
> BASH_SOURCE_PATH>/xxx/yyy/libzzz.bash"
>
> This might be useful when the middle path elements of the library
> location are ambiguous, yet the candidates are common with different
> $__dir__. However, I don't have an idea about whether this has a
> significant demand. What would be the use case? I naively think only
> `.' is normally useful for the suggested interpretation of relative
> paths.
>

That's fairly accurate.
I would expect there would normally be only one, but the utility is that it
can go anywhere between absolute paths, not just first or last.
It also leads automatically to (what I consider) the optimal result when
BASH_SOURCE_PATH is empty or unset.

A more sophisticated usage might be to load both "modules" and
"configuration settings" the same way:

BASH_SOURCE_PATH=../lib:/usr/share/fubar/bash-lib:${XDG_CONFIG_HOME:-$HOME/.local/config}/fubar/config:../config:/usr/share/fubar/config
source -i module1.bash
source -i custom_module.bash
source -i fubar.config

-Martin

Reply via email to