From b108ace00ab8e964ce761527628d5bb109813797 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Tue, 8 Jul 2025 15:17:05 +0200 Subject: [PATCH 1/5] code/binaries --- sh/code.awk | 5 +++++ sh/code.sh | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/sh/code.awk b/sh/code.awk index fba6da4..201db71 100644 --- a/sh/code.awk +++ b/sh/code.awk @@ -31,6 +31,7 @@ BEGIN { RE_FUNC = RE_SPACES "\\(" RE_SPACES "\\)" RE_SPACES "{" RE_ALIAS = RE_BEGIN "#=" RE_SPACES RE_VAR RE_END + RE_BINARY = RE_BEGIN "#\\|" RE_SPACES RE_VAR RE_END RE_CLOSE = RE_BEGIN "}" RE_SPACES RE_END RE_COMMAND = RE_BEGIN "#/" RE_SPACES RE_VAR RE_END RE_CONSTANT = RE_BEGIN RE_CONST RE_SET RE_END @@ -52,6 +53,10 @@ BEGIN { if (match($0, RE_ALIAS, m)) { print m[1] } + } else if (action == "binaries") { + if (match($0, RE_BINARY, m)) { + print m[1] + } } else if (action == "commands") { if (match($0, RE_COMMAND, m)) { print m[1] diff --git a/sh/code.sh b/sh/code.sh index 76881b1..f0f5474 100644 --- a/sh/code.sh +++ b/sh/code.sh @@ -18,6 +18,8 @@ _rwx_code_awk="$(cat "${RWX_ROOT_SYSTEM}/code.awk")" _rwx_code_aliases="" # cache for code aliases functions _rwx_code_aliases_functions="" +# cache for code binaries +_rwx_code_binaries="" # cache for code commands _rwx_code_commands="" # cache for code constants @@ -120,6 +122,11 @@ rwx_code_aliases_functions() { echo "${_rwx_code_aliases_functions}" } +# show the cached binaries +rwx_code_binaries() { + echo "${_rwx_code_binaries}" +} + # show the cached commands rwx_code_commands() { echo "${_rwx_code_commands}" @@ -182,6 +189,8 @@ rwx_code_load() { done < Date: Tue, 8 Jul 2025 15:26:34 +0200 Subject: [PATCH 2/5] binaries/dedupe --- sh/code.awk | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/sh/code.awk b/sh/code.awk index 201db71..4ef8e69 100644 --- a/sh/code.awk +++ b/sh/code.awk @@ -55,7 +55,7 @@ BEGIN { } } else if (action == "binaries") { if (match($0, RE_BINARY, m)) { - print m[1] + binaries[m[1]] = "" } } else if (action == "commands") { if (match($0, RE_COMMAND, m)) { @@ -148,3 +148,11 @@ BEGIN { } } } + +END { + if (action == "binaries") { + for (binary in binaries) { + print binary + } + } +} From 9b61976835711b62e238577f644336a191b6eb47 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Tue, 8 Jul 2025 15:48:13 +0200 Subject: [PATCH 3/5] commands/functions --- sh/code.awk | 12 ++++++++++++ sh/code.sh | 25 ++++++++++++++++++++++++- sh/test.sh | 3 ++- 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/sh/code.awk b/sh/code.awk index 4ef8e69..b722bec 100644 --- a/sh/code.awk +++ b/sh/code.awk @@ -85,6 +85,18 @@ BEGIN { } else { reset() } + } else if (action == "commands functions") { + if (match($0, RE_COMMAND, m)) { + append(m[1]) + } else if (match($0, RE_FUNCTION, m)) { + n = split(doc, array, "\n") + for (i = 1; i<= n; i++) { + print array[i] " " m[1] + } + reset() + } else { + reset() + } } else if (action == "doc") { # doc if (match($0, RE_SHEBANG, m)) { diff --git a/sh/code.sh b/sh/code.sh index f0f5474..8689552 100644 --- a/sh/code.sh +++ b/sh/code.sh @@ -22,6 +22,8 @@ _rwx_code_aliases_functions="" _rwx_code_binaries="" # cache for code commands _rwx_code_commands="" +# cache for code commands functions +_rwx_code_commands_functions="" # cache for code constants _rwx_code_constants="" # cache for code functions @@ -101,7 +103,7 @@ rwx_code_aliases() { echo "${_rwx_code_aliases}" } -# find aliased function +# find alias function rwx_code_alias_function() { local target="${1}" local line name @@ -116,6 +118,21 @@ ${_rwx_code_aliases_functions} EOF } +# find command function +rwx_code_command_function() { + local target="${1}" + local line name + while IFS= read -r line; do + name="$(echo "${line}" | awk "{print \$1}")" + if [ "${name}" = "${target}" ]; then + echo "${line}" | + awk "{print \$2}" + fi + done < Date: Tue, 8 Jul 2025 15:49:19 +0200 Subject: [PATCH 4/5] fix --- sh/code.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sh/code.sh b/sh/code.sh index 8689552..d0afc7e 100644 --- a/sh/code.sh +++ b/sh/code.sh @@ -254,7 +254,7 @@ rwx_code_main() { if [ -n "${command}" ]; then local function # find the matching function - function="$(rwx_code_alias_function "${command}")" + function="$(rwx_code_command_function "${command}")" if [ -n "${function}" ]; then "${function}" "${@}" fi From 967e17e224b43f322ae83152a94d7348d81f75e6 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Tue, 8 Jul 2025 15:54:55 +0200 Subject: [PATCH 5/5] parse/commands,functions --- sh/code.sh | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/sh/code.sh b/sh/code.sh index d0afc7e..d046dbb 100644 --- a/sh/code.sh +++ b/sh/code.sh @@ -200,10 +200,8 @@ rwx_code_doc() { } rwx_code_load() { - # parse aliases - _rwx_code_aliases="$(rwx_code_parse "aliases")" - # parse aliases functions local line text + # parse aliases functions _rwx_code_aliases_functions="$(rwx_code_parse "aliases functions")" while IFS= read -r line; do text="$(echo "${line}" | sed "s| |() { |")" @@ -212,6 +210,17 @@ rwx_code_load() { done <