[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Special PATH variable for sourcing scripts?
From: |
David Ongaro |
Subject: |
Re: Special PATH variable for sourcing scripts? |
Date: |
Mon, 29 Apr 2024 02:58:04 -0700 |
User-agent: |
Gnus/5.13 (Gnus v5.13) |
Matheus Afonso Martins Moreira writes:
> So it would be great if bash had a separate PATH variable
> meant specifically for sourcing bash library scripts.
> It could be called BASH_LIBRARY_PATH.
>
> Bash already has a BASH_LOADABLES_PATH[2] variable:
Considering the prior art and that "LOADABLES" is plural, shouldn't the
suggestion be BASH_LIBRARIES_PATH?
> Do you think this would be a good addition
> to bash? Would a patch be accepted?
> Please let me know if I should try.
I don't like blurring the semantics of . or source. Frankly I don't see
the need since I think bash is powerful enough to do what you want in a
function. E.g. you can define
include() {
local candidate path
while read -rd: path
do
candidate="$path/$1"
[[ -f $candidate ]] && source "$candidate" && break
done <<<"$BASH_LIBRARIES_PATH:" ||
{ echo >&2 "$1: no such file" && return 1; }
}
export BASH_LIBRARIES_PATH=$HOME/.local/lib/bash:/some/more/paths
and then do
include terminal
include arguments
where you need it. (Of course you may use a more descriptive name than
'include'.)
Having a dedicated function for this also makes it easy to add
autocompletion which only considers BASH_LIBRARIES_PATH.
Re: Special PATH variable for sourcing scripts?, Chet Ramey, 2024/04/22
Re: Special PATH variable for sourcing scripts?,
David Ongaro <=