Exactly. I sent to the GNU Bash mailing list patches that implement literally this. It worked like this:
# searches for the `some-module` file
# in some separate PATH just for libraries
# for example: ~/.local/share/bash/modules
source -l some-module
At some point someone said this was a schizophrenic idea and I just left. Patches are still on the mailing list. I have no idea what the maintainer did with them.I wasn't readily able to find where the discussion broke down, but I see that there's a -p <path> flag in bash 5.3.
The patch itself was pretty simple, it's just that the community argued a lot about this feature even though I validated the idea in the mailing list before I even cloned the repository. I remember arguing with one person for days only to learn later he hadn't even read the code I sent.
> I wasn't readily able to find where the discussion broke down
Somewhere around here:
https://lists.gnu.org/archive/html/bug-bash/2024-05/msg00352...
The maintainer was pretty nice, he was just looking for community consensus.
> I see that there's a -p <path> flag in bash 5.3
That's the solution the maintainer favored back then:
https://lists.gnu.org/archive/html/bug-bash/2024-05/msg00333...
https://lists.gnu.org/archive/html/bug-bash/2024-05/msg00337...
So in the end it did make it into bash in some form. It's not very ergonomic by default but that can be fixed by wrapping it in an alias or function. Good enough.
Looks like 5.3 was released just over a month ago too so pretty recent. I'm gonna update and start using it right away. Thanks, Chet Ramey!