Re: Re: Re: [PATCH 0/4] Add import builtin

2024-05-05 Thread Phi Debian
On Sat, May 4, 2024 at 4:44 AM Matheus Afonso Martins Moreira < math...@matheusmoreira.com> wrote: > > By "library system" I just mean the exact mechanism through which > bash will load a "library". By "library", I mean ordinary scripts > whose purpose is to collect related functions and variables

[PATCH 0/9] Add library mode to source builtin

2024-05-05 Thread Matheus Afonso Martins Moreira
Bash scripts can be tricky to get right so reusing proven solutions as shell script libraries is of immense value. However, the existing shell script sourcing mechanisms are suboptimal for this task. The source builtin uses the PATH variable for resolving file names which means they would have to

[PATCH 1/9] builtins: extract file content executor function

2024-05-05 Thread Matheus Afonso Martins Moreira
Extract into a dedicated helper function the code which loads the contents of a file and executes it in the current shell. This separates this useful functionality from the path resolution mechanism used by the source builtin, allowing new functionality to be built upon it. Signed-off-by: Matheus

[PATCH 2/9] findcmd: parameterize path variable in functions

2024-05-05 Thread Matheus Afonso Martins Moreira
The PATH variable is hard coded in the user command finder function. Transforming it into an argument allows reusing the file finding logic with variables other than PATH, making the code more flexible. Signed-off-by: Matheus Afonso Martins Moreira --- findcmd.c | 25 + 1

[PATCH 3/9] findcmd: define the user library finder function

2024-05-05 Thread Matheus Afonso Martins Moreira
The find_user_library function looks for bash library script files in the directories given by the BASH_LIBRARIES_PATH variable which are separate locations meant specifically for reusable modules. An additional variable is introduced in order to avoid having to manipulate the PATH. Normally, the

[PATCH 6/9] builtins/source: define library search function

2024-05-05 Thread Matheus Afonso Martins Moreira
The search_for_library function is considerably simpler: it loads absolute paths directly, or searches for libraries in the directories defined by BASH_LIBRARIES_PATH. Signed-off-by: Matheus Afonso Martins Moreira --- builtins/source.def | 14 ++ 1 file changed, 14 insertions(+) dif

[PATCH 7/9] builtins/source: add the -l|--library options

2024-05-05 Thread Matheus Afonso Martins Moreira
Passing these options to the source builtin enables library loading mode which restricts its search path to the directories defined by the BASH_LIBRARIES_PATH variable. Signed-off-by: Matheus Afonso Martins Moreira --- builtins/source.def | 23 +-- 1 file changed, 21 insertio

[PATCH 8/9] builtins/source: search libraries in library mode

2024-05-05 Thread Matheus Afonso Martins Moreira
Behave normally when executed without any options. Search for libraries when library mode is enabled via the -l or --library options. Signed-off-by: Matheus Afonso Martins Moreira --- builtins/source.def | 5 - 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/builtins/source.def

[PATCH 9/9] variables: define default BASH_LIBRARIES_PATH

2024-05-05 Thread Matheus Afonso Martins Moreira
Define a build time configurable default value for the new BASH_LIBRARIES_PATH variable. Look for libraries in the user's home directory as well as the system wide directories. Signed-off-by: Matheus Afonso Martins Moreira --- config-top.h | 7 +++ variables.c | 1 + 2 files changed, 8 inse

[PATCH 5/9] builtins/source: refactor file searching function

2024-05-05 Thread Matheus Afonso Martins Moreira
Extract the file searching algorithm of the source builtin into a static helper function. Makes the code easier to understand and separates the searching from the error handling logic. Signed-off-by: Matheus Afonso Martins Moreira --- builtins/source.def | 59 +++-

[PATCH 4/9] bashgetopt: define long option shortener function

2024-05-05 Thread Matheus Afonso Martins Moreira
Define the shorten_long_options helper function that converts long options to short options which are supported by bash's builting getopt function. Signed-off-by: Matheus Afonso Martins Moreira --- builtins/bashgetopt.c | 24 builtins/bashgetopt.h | 7 +++ 2 files c

Re: [PATCH 0/9] Add library mode to source builtin

2024-05-05 Thread Lawrence Velázquez
On Sun, May 5, 2024, at 5:54 AM, Matheus Afonso Martins Moreira wrote: > This patch set adds a special operating mode to the existing source > builtin to make it behave in the desired way. When source is passed > the options --library or -l, it will search for files in the > directories given by th

Re: [PATCH 0/4] Add import builtin

2024-05-05 Thread Lawrence Velázquez
On Sun, May 5, 2024, at 12:35 AM, Matheus Afonso Martins Moreira wrote: > I agree that a one line of code reduction is underwhelming > but that's not the only reason to include it. The users are the > main beneficiaries. This gives users a simple way to load > modules without using any module manag

Re: [PATCH 0/9] Add library mode to source builtin

2024-05-05 Thread Kerin Millar
On Sun, 5 May 2024, at 8:11 PM, Lawrence Velázquez wrote: > On Sun, May 5, 2024, at 5:54 AM, Matheus Afonso Martins Moreira wrote: >> This patch set adds a special operating mode to the existing source >> builtin to make it behave in the desired way. When source is passed >> the options --library o

Re: [PATCH 0/4] Add import builtin

2024-05-05 Thread Greg Wooledge
On Sun, May 05, 2024 at 03:32:04PM -0400, Lawrence Velázquez wrote: > Much like the periodic requests for XDG-organized startup files, a > BASH_SOURCE_PATH might be convenient but is not groundbreaking and > probably doesn't merit significant changes to the shell. I'm not > even convinced it merit

Re: Re: [PATCH 0/9] Add library mode to source builtin

2024-05-05 Thread Matheus Afonso Martins Moreira
> I think every single use of the term "library" in this whole endeavor > is misleading and misguided. I don't think so. A library is just a logical collection of code and data that you can use to implement software. This is a mechanism meant to load those libraries separately from executables. T

Re: Re: [PATCH 0/9] Add library mode to source builtin

2024-05-05 Thread Matheus Afonso Martins Moreira
> Such is the extent to which I concur that I find even -l to be irritating. Well, I don't concur at all. I think it's just the opposite. I think it's actually the source builtin which incorrectly implies that all sourced scripts are executables when they might actually be libraries and modules.

Re: [PATCH 0/4] Add import builtin

2024-05-05 Thread Phi Debian
On Sun, May 5, 2024 at 9:47 PM Greg Wooledge wrote: > On Sun, May 05, 2024 at 03:32:04PM -0400, Lawrence Velázquez wrote: > > > The idea to add a BASH_SOURCE_PATH variable that gets searched before, or > instead of, PATH when using the source builtin -- that sounds good. I > don't really underst

Re: Re: [PATCH 0/4] Add import builtin

2024-05-05 Thread Matheus Afonso Martins Moreira
> I fail to see how this could possibly save "thousands and thousands > of lines of code". How many lines of code were needed to implement the module managers? Probably a lot of lines. I guessed it was in the "thousands of lines" ballpark. However many lines that is, this feature would allow me t

Re: Re: [PATCH 0/9] Add library mode to source builtin

2024-05-05 Thread Phi Debian
On Mon, May 6, 2024 at 5:43 AM Matheus Afonso Martins Moreira < math...@matheusmoreira.com> wrote: > > I think every single use of the term "library" in this whole endeavor > > is misleading and misguided. > > I don't think so. A library is just a logical collection of code and data > that you can

Re: Re: [PATCH 0/4] Add import builtin

2024-05-05 Thread Phi Debian
On Mon, May 6, 2024 at 7:28 AM Matheus Afonso Martins Moreira < math...@matheusmoreira.com> wrote: > Yet the feature has been described as "irritating"! > I really don't understand the cause for this > and it's making me feel really unwelcome. > I think it is not personnal, you proposed something

Re: Re: Re: [PATCH 0/9] Add library mode to source builtin

2024-05-05 Thread Matheus Afonso Martins Moreira
> Libraries are 'compiled collection of object module', can be static/dynamic, > dynamic imply a runtime load. By this definition, dynamic languages and scripting languages don't have libraries. They clearly do have libraries. Sometimes they're called modules but it's the same thing. > This is