From 3da235e09e5e799f3062f1678fbf922d051819ad Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Fri, 4 Jul 2025 01:17:12 +0200 Subject: [PATCH 1/6] cache/same --- sh/main.sh | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/sh/main.sh b/sh/main.sh index 8d950b0..cec9997 100755 --- a/sh/main.sh +++ b/sh/main.sh @@ -69,24 +69,15 @@ rwx_cache() { local fill text fill="$(rwx_fill "${#name}" ─)" text="$(cat "${path}")" - case "${text}" in - "#!"*) - RWX_CODE="${text} - -# ╭───┬────┬─${fill}─╮ -# │ ↖ │ sh │ ${name} │ -# ╰───┴────┴─${fill}─╯" - ;; - *) - RWX_CODE="${RWX_CODE} - + [ -n "${RWX_CODE}" ] && RWX_CODE="${RWX_CODE} +" + RWX_CODE="${RWX_CODE}\ # ╭───┬────┬─${fill}─╮ # │ ↙ │ sh │ ${name} │ # ╰───┴────┴─${fill}─╯ -${text}" - ;; - esac +${text} +" } # ╭──────┬──────╮ From 47882c10fe5ff3504b98c644319b37c96da6e9ad Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Fri, 4 Jul 2025 03:35:51 +0200 Subject: [PATCH 2/6] doc/wip --- sh/main.sh | 26 ++++++-------------------- sh/self.sh | 54 +++++++++++++++++++++++++++++++++++++++++------------- 2 files changed, 47 insertions(+), 33 deletions(-) diff --git a/sh/main.sh b/sh/main.sh index cec9997..087c31b 100755 --- a/sh/main.sh +++ b/sh/main.sh @@ -8,6 +8,7 @@ # │ main │ constants │ # ╰──────┴───────────╯ +# name of the entrypoint file RWX_MAIN_NAME="main.sh" RWX_SELF_NAME="rwx" @@ -61,37 +62,22 @@ rwx_main() { # │ main │ cache │ # ╰──────┴───────╯ +RWX_CODE="" + +# cache source code of a module rwx_cache() { local root="${1}" local module="${2}" local name="${module%.sh}" local path="${root}/${module}" - local fill text - fill="$(rwx_fill "${#name}" ─)" + local text text="$(cat "${path}")" - [ -n "${RWX_CODE}" ] && RWX_CODE="${RWX_CODE} -" RWX_CODE="${RWX_CODE}\ -# ╭───┬────┬─${fill}─╮ -# │ ↙ │ sh │ ${name} │ -# ╰───┴────┴─${fill}─╯ - +#↓ ${name} ${text} " } -# ╭──────┬──────╮ -# │ main │ fill │ -# ╰──────┴──────╯ - -rwx_fill() { - local index="${1}" - while [ "${index}" -gt 0 ]; do - printf "%s" "${2}" - index=$((index - 1)) - done -} - # ╭──────┬────────╮ # │ main │ source │ # ╰──────┴────────╯ diff --git a/sh/self.sh b/sh/self.sh index 0a8f33e..eb9822d 100644 --- a/sh/self.sh +++ b/sh/self.sh @@ -1,22 +1,50 @@ +# self module + # meta doc rwx_doc() { local name="${1}" [ -n "${name}" ] || return - local doc line module - rwx_ifs_set - for module in $(rwx_find_shell "${RWX_ROOT_SYSTEM}"); do - while read -r line; do - case "${line}" in - "#"*) doc="${doc}${line}" ;; - "${name}() {") - echo "${doc}" - return + local constant doc func line module + printf "%s\n" "${RWX_CODE}" | while IFS= read -r line; do + case "${line}" in + "#!"*) doc="" ;; + "#↓"*) + doc="" + module="$(echo "${line}" | sed "s|#↓ \\(.*\\)|\\1|")" ;; - *) doc="" ;; - esac - done <"${RWX_ROOT_SYSTEM}/${module}" + "#"*) + [ -n "${doc}" ] && doc="${doc} +" + doc="${doc}${line}" + ;; + *"="*) + constant="$(echo "${line}" | sed "s|^\\(.*\\)=.*|\\1|")" + if [ "${constant}" = "${name}" ]; then + echo "${doc}" + return + else + doc="" + fi + ;; + *"("*")"*"{"*) + func="$(echo "${line}" | sed "s|^\\(.*\\)() {.*|\\1|")" + if [ "${func}" = "${name}" ]; then + echo "${doc}" + return + else + doc="" + fi + ;; + *) + if [ "${module}" = "${name}" ]; then + echo "${doc}" + return + else + doc="" + fi + ;; + esac done - rwx_ifs_unset } # ╭──────┬───────╮ From 651fafe418b8b0b537669063bcd42c705c79c2ed Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Fri, 4 Jul 2025 03:39:58 +0200 Subject: [PATCH 3/6] main/doc --- sh/main.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/sh/main.sh b/sh/main.sh index 087c31b..854a787 100755 --- a/sh/main.sh +++ b/sh/main.sh @@ -1,4 +1,5 @@ #! /usr/bin/env sh +# main module # ╭──────╮ # │ main │ From 80632463f6adb0ab215f88b2a5f6e084c5f8c91b Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Fri, 4 Jul 2025 03:52:38 +0200 Subject: [PATCH 4/6] =?UTF-8?q?=E2=88=92ifs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sh/main.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/sh/main.sh b/sh/main.sh index 854a787..88e7d00 100755 --- a/sh/main.sh +++ b/sh/main.sh @@ -187,22 +187,22 @@ rwx_parse() { local func="${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}" | + printf "%s\n" "${RWX_CODE}" | grep "${start}${constant}${setting}" | - sed "s|${start}\\(${constant}\\)${setting}|\\1|"); do + sed "s|${start}\\(${constant}\\)${setting}|\\1|" | + while IFS= read -r line; do RWX_CONSTANTS="${RWX_CONSTANTS}${line} " done RWX_FUNCTIONS="" - for line in $(echo "${RWX_CODE}" | + printf "%s\n" "${RWX_CODE}" | grep "${start}${id}${func}" | - sed "s|${start}\\(${id}\\)${func}|\\1|"); do + sed "s|${start}\\(${id}\\)${func}|\\1|" | + while IFS= read -r line; do RWX_FUNCTIONS="${RWX_FUNCTIONS}${line} " done - rwx_ifs_unset } # ╭──────┬─────╮ From 5346091e7b337a029338c27c7be893c6f39c42f6 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Fri, 4 Jul 2025 04:34:26 +0200 Subject: [PATCH 5/6] =?UTF-8?q?=E2=88=92ifs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sh/main.sh | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/sh/main.sh b/sh/main.sh index 88e7d00..75036ef 100755 --- a/sh/main.sh +++ b/sh/main.sh @@ -93,16 +93,17 @@ rwx_source() { count=0 __rwx_log "" \ ". ${root}" - rwx_ifs_set - for module in $(rwx_find_shell "${root}" "${file}"); do + local modules="$(rwx_find_shell "${root}" "${file}")" + while IFS= read -r module; do count=$((count + 1)) __rwx_log "$(printf "%02d" "${count}") ${module%.sh}" # shellcheck disable=SC1090 . "${root}/${module}" # cache code rwx_cache "${root}" "${module}" - done - rwx_ifs_unset + done < Date: Fri, 4 Jul 2025 04:53:46 +0200 Subject: [PATCH 6/6] subset/file,root --- sh/self.sh | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/sh/self.sh b/sh/self.sh index eb9822d..a7ebca2 100644 --- a/sh/self.sh +++ b/sh/self.sh @@ -155,16 +155,17 @@ export ENV=\"${RWX_MAIN_PATH}\" # ╰──────┴────────╯ rwx_self_subset() { - local argument path + local argument file root for argument in "${@}"; do - path="${RWX_ROOT_SYSTEM}/${argument}" - if [ -d "${path}" ]; then + root="${RWX_ROOT_SYSTEM}/${argument}" + file="${argument}.sh" + if [ -d "${root}" ]; then local file - for file in $(rwx_find_shell "${path}"); do + for file in $(rwx_find_shell "${root}"); do echo "${argument}/${file}" done - elif [ -f "${path}" ]; then - echo "${argument}" + elif [ -f "${RWX_ROOT_SYSTEM}/${file}" ]; then + echo "${file}" fi done }