From fe98428b6c08dc0e99922abffd508929254af963 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Mon, 7 Jul 2025 02:20:25 +0200 Subject: [PATCH 01/10] awk/functions --- sh/code.awk | 4 ++++ sh/main.sh | 6 ++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/sh/code.awk b/sh/code.awk index 053f1be..8a3208f 100644 --- a/sh/code.awk +++ b/sh/code.awk @@ -50,6 +50,10 @@ BEGIN { if (match($0, RE_ALIAS, m)) { print m[1] } + } else if (action == "functions") { + if (match($0, RE_FUNCTION, m)) { + print m[1] + } } else if (action == "aliases functions") { if (match($0, RE_ALIAS, m)) { append(m[1]) diff --git a/sh/main.sh b/sh/main.sh index 8fe2884..7d3f4b7 100755 --- a/sh/main.sh +++ b/sh/main.sh @@ -238,8 +238,10 @@ rwx_parse_constants() { sed --silent "s|${RWX_REGEX_TARGET_CONSTANT}|\\1|p" } rwx_parse_functions() { - printf "%s" "${_rwx_code}" | - sed --silent "s|${RWX_REGEX_TARGET_FUNCTION}|\\1|p" + echo "${_rwx_code}" | + awk \ + --assign action="functions" \ + "$(rwx_code_awk)" } rwx_parse_variables() { printf "%s" "${_rwx_code}" | From 17aaeb233d725dac04f35d2614eb7799f876c6f1 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Mon, 7 Jul 2025 02:21:50 +0200 Subject: [PATCH 02/10] lint --- sh/test.sh | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/sh/test.sh b/sh/test.sh index d017077..4f4a557 100644 --- a/sh/test.sh +++ b/sh/test.sh @@ -21,8 +21,7 @@ rwx_test_code() { "variables" \ "functions" \ "aliases" \ - "aliases_functions" \ - + "aliases_functions" rwx_code for items in "${@}"; do echo @@ -47,8 +46,7 @@ rwx_test_doc() { "rwx_cache" \ \ "alias/batcat" \ - "b" \ - + "b" for item in "${@}"; do echo rwx_code_doc "${item}" From dbfe0e1407188f3fc473cb462c4237919297d48b Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Mon, 7 Jul 2025 02:23:26 +0200 Subject: [PATCH 03/10] awk/variable --- sh/code.sh | 2 +- sh/main.sh | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/sh/code.sh b/sh/code.sh index 8838276..2ec9095 100644 --- a/sh/code.sh +++ b/sh/code.sh @@ -77,5 +77,5 @@ rwx_code_doc() { awk \ --assign action="doc" \ --assign target="${name}" \ - "$(rwx_code_awk)" + "${_rwx_code_awk}" } diff --git a/sh/main.sh b/sh/main.sh index 7d3f4b7..947f368 100755 --- a/sh/main.sh +++ b/sh/main.sh @@ -225,13 +225,13 @@ rwx_parse_aliases() { echo "${_rwx_code}" | awk \ --assign action="aliases" \ - "$(rwx_code_awk)" + "${_rwx_code_awk}" } rwx_parse_aliases_functions() { printf "%s" "${_rwx_code}" | awk \ --assign action="aliases functions" \ - "$(rwx_code_awk)" + "${_rwx_code_awk}" } rwx_parse_constants() { printf "%s" "${_rwx_code}" | @@ -241,7 +241,7 @@ rwx_parse_functions() { echo "${_rwx_code}" | awk \ --assign action="functions" \ - "$(rwx_code_awk)" + "${_rwx_code_awk}" } rwx_parse_variables() { printf "%s" "${_rwx_code}" | From fd281ee8d0c7aaec8e82f59b55f89c4fe1056201 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Mon, 7 Jul 2025 02:27:41 +0200 Subject: [PATCH 04/10] awk/constants --- sh/code.awk | 4 ++++ sh/main.sh | 12 +++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/sh/code.awk b/sh/code.awk index 8a3208f..76c7641 100644 --- a/sh/code.awk +++ b/sh/code.awk @@ -50,6 +50,10 @@ BEGIN { if (match($0, RE_ALIAS, m)) { print m[1] } + } else if (action == "constants") { + if (match($0, RE_CONSTANT, m)) { + print m[1] + } } else if (action == "functions") { if (match($0, RE_FUNCTION, m)) { print m[1] diff --git a/sh/main.sh b/sh/main.sh index 947f368..7c5b831 100755 --- a/sh/main.sh +++ b/sh/main.sh @@ -222,23 +222,25 @@ EOF _rwx_code_variables="$(rwx_parse_variables)" } rwx_parse_aliases() { - echo "${_rwx_code}" | + rwx_code | awk \ --assign action="aliases" \ "${_rwx_code_awk}" } rwx_parse_aliases_functions() { - printf "%s" "${_rwx_code}" | + rwx_code | awk \ --assign action="aliases functions" \ "${_rwx_code_awk}" } rwx_parse_constants() { - printf "%s" "${_rwx_code}" | - sed --silent "s|${RWX_REGEX_TARGET_CONSTANT}|\\1|p" + rwx_code | + awk \ + --assign action="constants" \ + "${_rwx_code_awk}" } rwx_parse_functions() { - echo "${_rwx_code}" | + rwx_code | awk \ --assign action="functions" \ "${_rwx_code_awk}" From 40bd26f9ced3f97f58e261b2a213d35f2679a93f Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Mon, 7 Jul 2025 02:31:01 +0200 Subject: [PATCH 05/10] awk/variables --- sh/code.awk | 4 ++++ sh/main.sh | 6 ++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/sh/code.awk b/sh/code.awk index 76c7641..65cccd6 100644 --- a/sh/code.awk +++ b/sh/code.awk @@ -58,6 +58,10 @@ BEGIN { if (match($0, RE_FUNCTION, m)) { print m[1] } + } else if (action == "variables") { + if (match($0, RE_CONSTANT, m)) { + print m[1] + } } else if (action == "aliases functions") { if (match($0, RE_ALIAS, m)) { append(m[1]) diff --git a/sh/main.sh b/sh/main.sh index 7c5b831..51799ce 100755 --- a/sh/main.sh +++ b/sh/main.sh @@ -246,8 +246,10 @@ rwx_parse_functions() { "${_rwx_code_awk}" } rwx_parse_variables() { - printf "%s" "${_rwx_code}" | - sed --silent "s|${RWX_REGEX_TARGET_VARIABLE}|\\1|p" + rwx_code | + awk \ + --assign action="variables" \ + "${_rwx_code_awk}" } # ╭──────┬─────╮ From 45f0ebbb9b65f32d577c59df1164508822a4e17d Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Mon, 7 Jul 2025 02:45:58 +0200 Subject: [PATCH 06/10] code/vars --- sh/code.sh | 24 +++++++++++++++++------- sh/main.sh | 20 -------------------- 2 files changed, 17 insertions(+), 27 deletions(-) diff --git a/sh/code.sh b/sh/code.sh index 2ec9095..49cc993 100644 --- a/sh/code.sh +++ b/sh/code.sh @@ -6,8 +6,18 @@ # │ code │ variables │ # ╰──────┴───────────╯ -# path to the required parsing awk script +# cache for the parsing awk script _rwx_code_awk="$(cat "${RWX_ROOT_SYSTEM}/code.awk")" +# cache for code aliases +_rwx_code_aliases="" +# cache for code aliases functions +_rwx_code_aliases_functions="" +# cache for code constants +_rwx_code_constants="" +# cache for code functions +_rwx_code_functions="" +# cache for code variables +_rwx_code_variables="" # ╭──────┬───────╮ # │ code │ parts │ @@ -19,6 +29,11 @@ rwx_code() { echo "${_rwx_code}" } +# show the cached awk script +rwx_code_awk() { + echo "${_rwx_code_awk}" +} + # show the cached aliases #= rca rwx_code_aliases() { @@ -31,11 +46,6 @@ rwx_code_aliases_functions() { echo "${_rwx_code_aliases_functions}" } -# show the cached awk script -rwx_code_awk() { - echo "${_rwx_code_awk}" -} - # show the cached constants #= rcc rwx_code_constants() { @@ -73,7 +83,7 @@ rwx_code_check() { rwx_code_doc() { local name="${1}" [ -n "${name}" ] || return - printf "%s" "${_rwx_code}" | + rwx_code | awk \ --assign action="doc" \ --assign target="${name}" \ diff --git a/sh/main.sh b/sh/main.sh index 51799ce..1bce024 100755 --- a/sh/main.sh +++ b/sh/main.sh @@ -181,26 +181,6 @@ rwx_find_shell() { # │ main │ parse │ # ╰──────┴───────╯ -RWX_REGEX_CONSTANT="[_A-Z][_0-9A-Z]*" -RWX_REGEX_FUNCTION="[_A-Za-z][_0-9A-Za-z]*" -RWX_REGEX_SET="=.*" -RWX_REGEX_SPACES="[[:space:]]*" -RWX_REGEX_VARIABLE="[_a-z][_0-9a-z]*" - -RWX_REGEX_BEGIN="^" -RWX_REGEX_OPEN="\ -${RWX_REGEX_SPACES}(${RWX_REGEX_SPACES})${RWX_REGEX_SPACES}{.*" - -RWX_REGEX_TARGET_CONSTANT="\ -${RWX_REGEX_BEGIN}\\(${RWX_REGEX_CONSTANT}\\)${RWX_REGEX_SET}" -RWX_REGEX_TARGET_FUNCTION="\ -${RWX_REGEX_BEGIN}\\(${RWX_REGEX_FUNCTION}\\)${RWX_REGEX_OPEN}" -RWX_REGEX_TARGET_VARIABLE="\ -${RWX_REGEX_BEGIN}\\(${RWX_REGEX_VARIABLE}\\)${RWX_REGEX_SET}" - -# cache for code variables -_rwx_code_variables="" - rwx_parse_code() { # parse aliases _rwx_code_aliases="$(rwx_parse_aliases)" From 0b12a7545e9b42a140fe868206cb4fc4cfdd37b4 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Mon, 7 Jul 2025 02:58:39 +0200 Subject: [PATCH 07/10] code/load --- sh/code.sh | 51 ++++++++++++++++++++++++++++++++++++++++++++++ sh/main.sh | 59 ++---------------------------------------------------- 2 files changed, 53 insertions(+), 57 deletions(-) diff --git a/sh/code.sh b/sh/code.sh index 49cc993..c676235 100644 --- a/sh/code.sh +++ b/sh/code.sh @@ -89,3 +89,54 @@ rwx_code_doc() { --assign target="${name}" \ "${_rwx_code_awk}" } + +rwx_code_load() { + # parse aliases + _rwx_code_aliases="$(rwx_parse_aliases)" + # parse aliases functions + local line text + _rwx_code_aliases_functions="$(rwx_parse_aliases_functions)" + while IFS= read -r line; do + text="$(echo "${line}" | sed "s| |() { |")" + text="${text} \"\${@}\"; }" + eval "${text}" + done < Date: Mon, 7 Jul 2025 03:01:21 +0200 Subject: [PATCH 08/10] code/parse --- sh/code.sh | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/sh/code.sh b/sh/code.sh index c676235..31339f6 100644 --- a/sh/code.sh +++ b/sh/code.sh @@ -110,6 +110,15 @@ EOF # parse variables _rwx_code_variables="$(rwx_parse_variables)" } + +rwx_code_parse() { + local action="${1}" + rwx_code | + awk \ + --assign action="${action}" \ + "${_rwx_code_awk}" +} + rwx_parse_aliases() { rwx_code | awk \ From b2e965da92ea251e704aedb9235dd74e05500905 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Mon, 7 Jul 2025 03:07:28 +0200 Subject: [PATCH 09/10] code/parse --- sh/code.sh | 41 +++++------------------------------------ 1 file changed, 5 insertions(+), 36 deletions(-) diff --git a/sh/code.sh b/sh/code.sh index 31339f6..e5a898b 100644 --- a/sh/code.sh +++ b/sh/code.sh @@ -92,10 +92,10 @@ rwx_code_doc() { rwx_code_load() { # parse aliases - _rwx_code_aliases="$(rwx_parse_aliases)" + _rwx_code_aliases="$(rwx_code_parse "aliases")" # parse aliases functions local line text - _rwx_code_aliases_functions="$(rwx_parse_aliases_functions)" + _rwx_code_aliases_functions="$(rwx_code_parse "aliases functions")" while IFS= read -r line; do text="$(echo "${line}" | sed "s| |() { |")" text="${text} \"\${@}\"; }" @@ -104,11 +104,11 @@ rwx_code_load() { ${_rwx_code_aliases_functions} EOF # parse constants - _rwx_code_constants="$(rwx_parse_constants)" + _rwx_code_constants="$(rwx_code_parse "constants")" # parse functions - _rwx_code_functions="$(rwx_parse_functions)" + _rwx_code_functions="$(rwx_code_parse "functions")" # parse variables - _rwx_code_variables="$(rwx_parse_variables)" + _rwx_code_variables="$(rwx_code_parse "variables")" } rwx_code_parse() { @@ -118,34 +118,3 @@ rwx_code_parse() { --assign action="${action}" \ "${_rwx_code_awk}" } - -rwx_parse_aliases() { - rwx_code | - awk \ - --assign action="aliases" \ - "${_rwx_code_awk}" -} -rwx_parse_aliases_functions() { - rwx_code | - awk \ - --assign action="aliases functions" \ - "${_rwx_code_awk}" -} -rwx_parse_constants() { - rwx_code | - awk \ - --assign action="constants" \ - "${_rwx_code_awk}" -} -rwx_parse_functions() { - rwx_code | - awk \ - --assign action="functions" \ - "${_rwx_code_awk}" -} -rwx_parse_variables() { - rwx_code | - awk \ - --assign action="variables" \ - "${_rwx_code_awk}" -} From 3ccfc82cf26511cd5227f24614d4654b482a1a2b Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Mon, 7 Jul 2025 03:09:02 +0200 Subject: [PATCH 10/10] fix --- sh/code.awk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sh/code.awk b/sh/code.awk index 65cccd6..0d23127 100644 --- a/sh/code.awk +++ b/sh/code.awk @@ -59,7 +59,7 @@ BEGIN { print m[1] } } else if (action == "variables") { - if (match($0, RE_CONSTANT, m)) { + if (match($0, RE_VARIABLE, m)) { print m[1] } } else if (action == "aliases functions") {