From 706847f746cfab84d808250908c11b0fb4e7452f Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Thu, 3 Jul 2025 18:14:56 +0200 Subject: [PATCH 01/11] source/root --- sh/main.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/sh/main.sh b/sh/main.sh index 63ca6bf..2798080 100755 --- a/sh/main.sh +++ b/sh/main.sh @@ -59,18 +59,18 @@ rwx_main() { # source code from file path rwx_source() { - local path="${1}" - [ -d "${path}" ] || + local root="${1}" + [ -d "${root}" ] || return 1 local count module count=0 __rwx_log "" \ - ". ${path}" + ". ${root}" rwx_ifs_set - for module in $(rwx_find_shell "${path}" "${RWX_MAIN_NAME}"); do + for module in $(rwx_find_shell "${root}" "${RWX_MAIN_NAME}"); do count=$((count + 1)) __rwx_log "$(printf "%02d" "${count}") ${module%.sh}" - module="${path}/${module}" + module="${root}/${module}" # shellcheck disable=SC1090 . "${module}" done From ebc41e8a53e575ac45b63ab71f010346a3bccecd Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Thu, 3 Jul 2025 20:42:59 +0200 Subject: [PATCH 02/11] source/file --- sh/main.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sh/main.sh b/sh/main.sh index 2798080..ed795fc 100755 --- a/sh/main.sh +++ b/sh/main.sh @@ -38,7 +38,7 @@ RWX_MAIN_PATH="${RWX_ROOT_SYSTEM}/${RWX_MAIN_NAME}" # run initial steps rwx_main() { # source system root - if ! rwx_source "${RWX_ROOT_SYSTEM}"; then + if ! rwx_source "${RWX_ROOT_SYSTEM}" "${RWX_MAIN_NAME}"; then __rwx_log "Not a directory: ${RWX_ROOT_SYSTEM}" return 1 fi @@ -62,12 +62,13 @@ rwx_source() { local root="${1}" [ -d "${root}" ] || return 1 + local file="${2}" local count module count=0 __rwx_log "" \ ". ${root}" rwx_ifs_set - for module in $(rwx_find_shell "${root}" "${RWX_MAIN_NAME}"); do + for module in $(rwx_find_shell "${root}" "${file}"); do count=$((count + 1)) __rwx_log "$(printf "%02d" "${count}") ${module%.sh}" module="${root}/${module}" From 8c55351aaecb2f915613021ad22a9820c3207116 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Thu, 3 Jul 2025 21:11:39 +0200 Subject: [PATCH 03/11] cache/wip --- sh/main.sh | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/sh/main.sh b/sh/main.sh index ed795fc..81c65cd 100755 --- a/sh/main.sh +++ b/sh/main.sh @@ -37,6 +37,8 @@ RWX_MAIN_PATH="${RWX_ROOT_SYSTEM}/${RWX_MAIN_NAME}" # run initial steps rwx_main() { + # cache main + rwx_cache "${RWX_ROOT_SYSTEM}" "${RWX_MAIN_NAME}" # source system root if ! rwx_source "${RWX_ROOT_SYSTEM}" "${RWX_MAIN_NAME}"; then __rwx_log "Not a directory: ${RWX_ROOT_SYSTEM}" @@ -53,6 +55,28 @@ rwx_main() { fi } +# ╭──────┬───────╮ +# │ main │ cache │ +# ╰──────┴───────╯ + +rwx_cache() { + local root="${1}" + local module="${2}" + local name="${module%.sh}" + local path="${root}/${module}" + local text="$(cat "${path}")" + case "${text}" in + "#!"*) RWX_CODE="${text}" ;; + *) RWX_CODE="${RWX_CODE} + +# ╭╮ +# │ ${name} │ +# ╰╯ + +${text}" ;; + esac +} + # ╭──────┬────────╮ # │ main │ source │ # ╰──────┴────────╯ @@ -71,9 +95,10 @@ rwx_source() { for module in $(rwx_find_shell "${root}" "${file}"); do count=$((count + 1)) __rwx_log "$(printf "%02d" "${count}") ${module%.sh}" - module="${root}/${module}" # shellcheck disable=SC1090 - . "${module}" + . "${root}/${module}" + # cache code + rwx_cache "${root}" "${module}" done rwx_ifs_unset } From 94689a23bfa4332a9aae65aea3cbfc0ddb3c2809 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Thu, 3 Jul 2025 21:27:44 +0200 Subject: [PATCH 04/11] cache/fill --- sh/main.sh | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/sh/main.sh b/sh/main.sh index 81c65cd..c7ca19a 100755 --- a/sh/main.sh +++ b/sh/main.sh @@ -67,16 +67,31 @@ rwx_cache() { local text="$(cat "${path}")" case "${text}" in "#!"*) RWX_CODE="${text}" ;; - *) RWX_CODE="${RWX_CODE} + *) + local fill="$(rwx_fill "${#name}" ─)" + RWX_CODE="${RWX_CODE} -# ╭╮ -# │ ${name} │ -# ╰╯ +# ╭───┬─${fill}─╮ +# │ ↙ │ ${name} │ +# ╰───┴─${fill}─╯ -${text}" ;; +${text}" + ;; esac } +# ╭──────┬──────╮ +# │ main │ fill │ +# ╰──────┴──────╯ + +rwx_fill() { + local index="${1}" + while [ "${index}" -gt 0 ]; do + printf "%s" "${2}" + index=$((index - 1)) + done +} + # ╭──────┬────────╮ # │ main │ source │ # ╰──────┴────────╯ From 12561ee50594bf23a581efeb1f327dd64c7deb8d Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Thu, 3 Jul 2025 21:32:52 +0200 Subject: [PATCH 05/11] .sh --- sh/main.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sh/main.sh b/sh/main.sh index c7ca19a..725995e 100755 --- a/sh/main.sh +++ b/sh/main.sh @@ -71,9 +71,9 @@ rwx_cache() { local fill="$(rwx_fill "${#name}" ─)" RWX_CODE="${RWX_CODE} -# ╭───┬─${fill}─╮ -# │ ↙ │ ${name} │ -# ╰───┴─${fill}─╯ +# ╭───┬─${fill}─┬────╮ +# │ ↙ │ ${name} │ sh │ +# ╰───┴─${fill}─┴────╯ ${text}" ;; From 72200668a9fef2c05be555127b7299753b5931a3 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Thu, 3 Jul 2025 21:38:36 +0200 Subject: [PATCH 06/11] sh/main --- sh/main.sh | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/sh/main.sh b/sh/main.sh index 725995e..d1ea522 100755 --- a/sh/main.sh +++ b/sh/main.sh @@ -63,17 +63,23 @@ rwx_cache() { local root="${1}" local module="${2}" local name="${module%.sh}" + local fill="$(rwx_fill "${#name}" ─)" local path="${root}/${module}" local text="$(cat "${path}")" case "${text}" in - "#!"*) RWX_CODE="${text}" ;; + "#!"*) + RWX_CODE="${text} + +# ╭───┬────┬─${fill}─╮ +# │ ↖ │ sh │ ${name} │ +# ╰───┴────┴─${fill}─╯" + ;; *) - local fill="$(rwx_fill "${#name}" ─)" RWX_CODE="${RWX_CODE} -# ╭───┬─${fill}─┬────╮ -# │ ↙ │ ${name} │ sh │ -# ╰───┴─${fill}─┴────╯ +# ╭───┬────┬─${fill}─╮ +# │ ↙ │ sh │ ${name} │ +# ╰───┴────┴─${fill}─╯ ${text}" ;; From 2a6bfab4f9248ff38a898b8bff1afae837c0c7dd Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Thu, 3 Jul 2025 21:45:15 +0200 Subject: [PATCH 07/11] user_id --- sh/util.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sh/util.sh b/sh/util.sh index 38fe29a..ac6a9e0 100644 --- a/sh/util.sh +++ b/sh/util.sh @@ -49,7 +49,9 @@ rwx_remove() { } rwx_root() { - if [ "$(id --user)" -eq 0 ]; then + local user_id + user_id="$(id --user)" + if [ "${user_id}" -eq 0 ]; then return 0 else return 1 From bb8bedae27a18909baa2538668228b0def86054f Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Thu, 3 Jul 2025 21:47:57 +0200 Subject: [PATCH 08/11] lint/fill,text --- sh/main.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sh/main.sh b/sh/main.sh index d1ea522..4cd27ae 100755 --- a/sh/main.sh +++ b/sh/main.sh @@ -63,9 +63,10 @@ rwx_cache() { local root="${1}" local module="${2}" local name="${module%.sh}" - local fill="$(rwx_fill "${#name}" ─)" local path="${root}/${module}" - local text="$(cat "${path}")" + local fill text + fill="$(rwx_fill "${#name}" ─)" + text="$(cat "${path}")" case "${text}" in "#!"*) RWX_CODE="${text} From 2a9169947ec6855b6a9b507635d2d099a3542ec5 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Thu, 3 Jul 2025 22:18:02 +0200 Subject: [PATCH 09/11] root/shrink --- sh/util.sh | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/sh/util.sh b/sh/util.sh index ac6a9e0..13c70f5 100644 --- a/sh/util.sh +++ b/sh/util.sh @@ -51,11 +51,7 @@ rwx_remove() { rwx_root() { local user_id user_id="$(id --user)" - if [ "${user_id}" -eq 0 ]; then - return 0 - else - return 1 - fi + [ "${user_id}" -eq 0 ] || return 1 } rwx_warn_wipe() { From 6a73a8a740619c0e365e778031174a6196791323 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Fri, 4 Jul 2025 00:26:44 +0200 Subject: [PATCH 10/11] parse/functions --- sh/main.sh | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/sh/main.sh b/sh/main.sh index 4cd27ae..5cb772c 100755 --- a/sh/main.sh +++ b/sh/main.sh @@ -195,6 +195,26 @@ rwx_find_shell() { rwx_find_extension "sh" "${@}" } +# ╭──────┬───────╮ +# │ main │ parse │ +# ╰──────┴───────╯ + +rwx_parse() { + local ws="[[:space:]]*" + local fn="${ws}(${ws})${ws}{" + local id="[_a-zA-Z][_a-z0-9A-Z]*" + local line + rwx_ifs_set + RWX_FUNCTIONS="" + for line in $(echo "${RWX_CODE}" | + grep "^${ws}${id}${fn}" | + sed "s|^${ws}\\(${id}\\)${fn}.*|\\1|"); do + RWX_FUNCTIONS="${RWX_FUNCTIONS}${line} +" + done + rwx_ifs_unset +} + # ╭──────┬─────╮ # │ main │ run │ # ╰──────┴─────╯ From 8fd6beed112754931f3d491241cb75d8f6953029 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Fri, 4 Jul 2025 00:47:18 +0200 Subject: [PATCH 11/11] parse/constants --- sh/main.sh | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/sh/main.sh b/sh/main.sh index 5cb772c..d75695b 100755 --- a/sh/main.sh +++ b/sh/main.sh @@ -46,6 +46,8 @@ rwx_main() { fi # source user root rwx_source "${RWX_SELF_USER}" + # parse code cache + rwx_parse # context / command if [ -n "${RWX_COMMAND_NAME}" ]; then "${RWX_SELF_COMMAND}${RWX_COMMAND_NAME}" "${@}" @@ -201,14 +203,24 @@ rwx_find_shell() { rwx_parse() { local ws="[[:space:]]*" + local start="^${ws}" + local constant="[_A-Z][_0-9A-Z]*" + local setting="=.*" local fn="${ws}(${ws})${ws}{" local id="[_a-zA-Z][_a-z0-9A-Z]*" local line rwx_ifs_set + RWX_CONSTANTS="" + for line in $(echo "${RWX_CODE}" | + grep "${start}${constant}${setting}" | + sed "s|${start}\\(${constant}\\)${setting}|\\1|"); do + RWX_CONSTANTS="${RWX_CONSTANTS}${line} +" + done RWX_FUNCTIONS="" for line in $(echo "${RWX_CODE}" | - grep "^${ws}${id}${fn}" | - sed "s|^${ws}\\(${id}\\)${fn}.*|\\1|"); do + grep "${start}${id}${fn}" | + sed "s|${start}\\(${id}\\)${fn}.*|\\1|"); do RWX_FUNCTIONS="${RWX_FUNCTIONS}${line} " done