3 ms·
This honestly should be the default for all scripts. There are so many little annoyances in bash that would make it great if they were changed and improved. Sad
by matheusmoreira 1y ago
This honestly should be the default for all scripts. There are so many little annoyances in bash that would make it great if they were changed and improved. Sadly there's just no changing certain things.
My number one wishlist feature was a simple library system. Essentially just let me source files by name by searching in some standard user location. I actually wrote and submitted patches for this but it just didn't work out. Maintained my own version for a while and it was nice but not enough to justify the maintenance burden. Bash's number one feature is being the historical default shell on virtually every Linux distribution, without that there's no point.
At least we've got shellcheck.
- dhamidi 1y agoThe `source` builtin searches through all directories on PATH, not quite a library system, but useable with a bit of discipline in the to-be-sourced shellscripts.
- matheusmoreira 1y agoYeah. I sent patches that added a flag that made it search special library paths instead. source -l some-library
- abathur 1y agoWhen you say library system, do you mean something more or less like a separate search path and tools for managing it? I've written a little about how we can more or less accomplish something like meaningfully-reusable shell libraries in the nix ecosystem. I think https://www.t-ravis.com/post/shell/the_missing_comprehensive_package_manager_for_shell/ https://www.t-ravis.com/post/shell/the_missing_comprehensive... lays out the general idea but you can also pick through how my bashrc integrates libraries/modules (https://github.com/abathur/bashrc.nix https://github.com/abathur/bashrc.nix). (I'm just dropping these in bin, since that works with existing search path for source. Not ideal, but the generally explicit nature of dependencies in nix minimizes how much things can leak where they aren't meant to go.)
- matheusmoreira 1y ago> do you mean something more or less like a separate search path 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.
- abathur 1y agoIt seems reasonable to me. Sorry you got that reaction. Just from the mailing list thread size alone, it looks like you put quite a lot of work into it. 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.
- matheusmoreira 1y ago> Just from the mailing list thread size alone, it looks like you put quite a lot of work into it. 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.html 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.html https://lists.gnu.org/archive/html/bug-bash/2024-05/msg00333... https://lists.gnu.org/archive/html/bug-bash/2024-05/msg00337.html 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!
- oneshtein 1y agobash-modules project tries to implement "modules", which works in strict mode, but it got no traction.
- matheusmoreira 1y agoAccording to the mailing list there are dozens of such projects. As far as I can tell I'm the only person who was crazy enough to try to add this to bash itself as a native feature.