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
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
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
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
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
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
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
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
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
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 +++-
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
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
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
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
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
> 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
> 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.
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
> 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
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
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
> 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
22 matches
Mail list logo