From a32dceff1ecee70cd9b7541a6e8e82b14bd01e10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ionu=C8=9B=20G=2E=20Stan?= Date: Fri, 20 Sep 2024 19:58:34 +0300 Subject: [PATCH] bash: configure default value of BASH_LOADABLES_PATH See: https://www.gnu.org/software/bash/manual/html_node/Bash-Builtins.html#index-enable See: http://git.savannah.gnu.org/cgit/bash.git/tree/config-top.h#n80 This enables shorter syntax for loading stock Bash builtins. For example, instead of doing this: enable -f $(brew --prefix)/lib/bash/csv csv the user can now load the `csv` builtin directly: enable csv To complete the example, we can now do this: $ echo $BASH_LOADABLES_PATH /opt/homebrew/Cellar/bash/5.2.32/lib/bash:/usr/local/lib/bash:/usr/lib/bash:/opt/local/lib/bash:/usr/pkg/lib/bash:/opt/pkg/lib/bash:. $ type csv -bash: type: csv: not found $ enable csv $ type csv csv is a shell builtin $ help csv csv: csv [-a ARRAY] string Read comma-separated fields from a string. Parse STRING, a line of comma-separated values, into individual fields, and store them into the indexed array ARRAYNAME starting at index 0. If ARRAYNAME is not supplied, "CSV" is the default array name. $ csv 'a,"b",c' $ declare -p CSV declare -a CSV=([0]="a" [1]="b" [2]="c") $ enable -n csv $ type csv -bash: type: csv: not found --- Formula/b/bash.rb | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/Formula/b/bash.rb b/Formula/b/bash.rb index 2c026ea90052..352ba55ca701 100644 --- a/Formula/b/bash.rb +++ b/Formula/b/bash.rb @@ -112,11 +112,24 @@ def install # Homebrew's bash instead of /bin/bash. ENV.append_to_cflags "-DSSH_SOURCE_BASHRC" + bash_loadables_path=[ + "#{lib}/bash", + # Stock Bash paths; keep them for backwards compatibility. + "/usr/local/lib/bash", + "/usr/lib/bash", + "/opt/local/lib/bash", + "/usr/pkg/lib/bash", + "/opt/pkg/lib/bash", + ".", + ].join(":") + ENV.append_to_cflags "-DDEFAULT_LOADABLE_BUILTINS_PATH='\"#{bash_loadables_path}\"'" + system "./configure", "--prefix=#{prefix}" system "make", "install" end test do - assert_equal "hello", shell_output("#{bin}/bash -c \"echo -n hello\"") + assert_equal "hello", shell_output("#{bin}/bash -c 'echo -n hello'") + assert_equal "csv is a shell builtin\n", shell_output("#{bin}/bash -c 'enable csv; type csv'") end end