From 24a931cbfc884e873d5f25068155b7c658f6e361 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Mon, 7 Jul 2025 23:38:09 +0200 Subject: [PATCH 01/11] shell/mv --- sh/main.sh | 3 --- sh/shell/0.sh | 3 +++ 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/sh/main.sh b/sh/main.sh index 470cf72..16ce907 100755 --- a/sh/main.sh +++ b/sh/main.sh @@ -26,9 +26,6 @@ RWX_SELF_NAME="rwx" # │ main │ variables │ # ╰──────┴───────────╯ -# currently running shell name -RWX_SHELL="$(cat "/proc/${$}/comm")" - # system root directory of the project RWX_ROOT_SYSTEM="/usr/local/lib/${RWX_SELF_NAME}" # user root directory of the project diff --git a/sh/shell/0.sh b/sh/shell/0.sh index 6a28c31..c52639b 100644 --- a/sh/shell/0.sh +++ b/sh/shell/0.sh @@ -2,6 +2,9 @@ # │ shell │ # ╰───────╯ +# currently running shell name +RWX_SHELL="$(cat "/proc/${$}/comm")" + _rwx_shell_color() { local code="${1}" case "${RWX_SHELL}" in From 51cb88d0d3d77514ca8cdf3d2093c21c78fea6ad Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Mon, 7 Jul 2025 23:44:45 +0200 Subject: [PATCH 02/11] shell/shortcuts --- sh/alias/shell.sh | 18 ------------------ sh/shell/0.sh | 26 ++++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 18 deletions(-) delete mode 100644 sh/alias/shell.sh diff --git a/sh/alias/shell.sh b/sh/alias/shell.sh deleted file mode 100644 index f216c92..0000000 --- a/sh/alias/shell.sh +++ /dev/null @@ -1,18 +0,0 @@ -# shorten alias -a() { - alias \ - "${@}" -} - -# swap directory (current ↔ previous) -sd() { - cd \ - - || - return -} - -# exit terminal -x() { - exit \ - "${@}" -} diff --git a/sh/shell/0.sh b/sh/shell/0.sh index c52639b..ed847cb 100644 --- a/sh/shell/0.sh +++ b/sh/shell/0.sh @@ -130,6 +130,32 @@ rwx_shell_prompt() { printf "%b" "${view}" } +# ╭───────┬───────────╮ +# │ shell │ shortcuts │ +# ╰───────┴───────────╯ + +# shorten alias +#= a +rwx_shell_alias() { + alias \ + "${@}" +} + +# swap directory (current ↔ previous) +#= sd +rwx_shell_swap_directory() { + cd \ + - || + return +} + +# exit terminal +#= x +rwx_shell_exit() { + exit \ + "${@}" +} + # ╭───────┬──────╮ # │ shell │ main │ # ╰───────┴──────╯ From cc1f8f816abbddb78dd957259404f342e3fbe4c3 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Tue, 8 Jul 2025 00:05:07 +0200 Subject: [PATCH 03/11] code/commands --- sh/code.awk | 10 ++++++++++ sh/code.sh | 13 +++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/sh/code.awk b/sh/code.awk index 0d23127..efada06 100644 --- a/sh/code.awk +++ b/sh/code.awk @@ -32,6 +32,7 @@ BEGIN { RE_ALIAS = 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 RE_DOC = RE_BEGIN RE_SPACES "#" RE_SPACE RE_ANY RE_END RE_FUNCTION = RE_BEGIN RE_VAR RE_FUNC RE_END @@ -50,6 +51,10 @@ BEGIN { if (match($0, RE_ALIAS, m)) { print m[1] } + } else if (action == "commands") { + if (match($0, RE_COMMAND, m)) { + print m[1] + } } else if (action == "constants") { if (match($0, RE_CONSTANT, m)) { print m[1] @@ -89,6 +94,11 @@ BEGIN { if (m[1] == target) { alias = 1 } + } else if (match($0, RE_COMMAND, m)) { + append("/ " m[1]) + if (m[1] == target) { + alias = 1 + } # set } else if (match($0, RE_CONSTANT, m)) { if (m[1] == target) { diff --git a/sh/code.sh b/sh/code.sh index 76487b9..de4b331 100644 --- a/sh/code.sh +++ b/sh/code.sh @@ -12,6 +12,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 commands +_rwx_code_commands="" # cache for code constants _rwx_code_constants="" # cache for code functions @@ -23,7 +25,7 @@ _rwx_code_variables="" # │ code │ install │ # ╰──────┴─────────╯ -#= rwx_install +#/ rwx_install rwx_code_install() { local target="${1}" local command file name root @@ -44,7 +46,7 @@ rwx_code_install() { rwx_remove "${file}" rwx_link "${file}" "${name}" done < Date: Tue, 8 Jul 2025 00:44:25 +0200 Subject: [PATCH 04/11] rwx/code --- sh/main.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sh/main.sh b/sh/main.sh index 16ce907..9d79661 100755 --- a/sh/main.sh +++ b/sh/main.sh @@ -26,6 +26,9 @@ RWX_SELF_NAME="rwx" # │ main │ variables │ # ╰──────┴───────────╯ +# cache of all sourced code modules +_rwx_code="" + # system root directory of the project RWX_ROOT_SYSTEM="/usr/local/lib/${RWX_SELF_NAME}" # user root directory of the project @@ -77,9 +80,6 @@ rwx_main() { # │ main │ cache │ # ╰──────┴───────╯ -# cache of all sourced code modules -_rwx_code="" - # cache source code of a module # inside a global code variable rwx_cache() { From cd1701fb7159aae79cc5428d9a5538aa7feabc62 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Tue, 8 Jul 2025 00:48:18 +0200 Subject: [PATCH 05/11] main/main,cache --- sh/main.sh | 120 +++++++++++++++++++++++++++-------------------------- 1 file changed, 61 insertions(+), 59 deletions(-) diff --git a/sh/main.sh b/sh/main.sh index 9d79661..dd3628c 100755 --- a/sh/main.sh +++ b/sh/main.sh @@ -37,65 +37,6 @@ RWX_SELF_USER="${HOME}/${RWX_SELF_NAME}" # path to the entrypoint main file of the project RWX_MAIN_PATH="${RWX_ROOT_SYSTEM}/${RWX_MAIN_NAME}" -# ╭──────┬──────╮ -# │ main │ main │ -# ╰──────┴──────╯ - -# 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}" - return 1 - fi - # source user root - rwx_source "${RWX_SELF_USER}" - # load code cache - rwx_code_load - # context / command - local command - # command name used to run - # (stripped from hyphen interactive flag) - command="$(basename "${0}" | sed "s|^-||")" - case "${command}" in - "bash" | "dash" | "sh") unset command ;; - *) ;; - esac - if [ -n "${command}" ]; then - local function - # find the matching function - function="$(rwx_code_alias_function "${command}")" - if [ -n "${function}" ]; then - "${function}" "${@}" - fi - # context / shell - else - rwx_self_init - fi -} - -# ╭──────┬───────╮ -# │ main │ cache │ -# ╰──────┴───────╯ - -# cache source code of a module -# inside a global code variable -rwx_cache() { - local root="${1}" - local module="${2}" - local name="${module%.sh}" - local path="${root}/${module}" - local text - text="$(cat "${path}")" - # all source code - _rwx_code="${_rwx_code}\ -#. ${name} -${text} -" -} - # ╭──────┬────────╮ # │ main │ source │ # ╰──────┴────────╯ @@ -176,6 +117,67 @@ rwx_find_shell() { rwx_find_extension "sh" "${@}" } +################################################################################ + +# ╭──────┬───────╮ +# │ main │ cache │ +# ╰──────┴───────╯ + +# cache source code of a module +# inside a global code variable +rwx_cache() { + local root="${1}" + local module="${2}" + local name="${module%.sh}" + local path="${root}/${module}" + local text + text="$(cat "${path}")" + # all source code + _rwx_code="${_rwx_code}\ +#. ${name} +${text} +" +} + +# ╭──────┬──────╮ +# │ main │ main │ +# ╰──────┴──────╯ + +# 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}" + return 1 + fi + # source user root + rwx_source "${RWX_SELF_USER}" + # load code cache + rwx_code_load + # context / command + local command + # command name used to run + # (stripped from hyphen interactive flag) + command="$(basename "${0}" | sed "s|^-||")" + case "${command}" in + "bash" | "dash" | "sh") unset command ;; + *) ;; + esac + if [ -n "${command}" ]; then + local function + # find the matching function + function="$(rwx_code_alias_function "${command}")" + if [ -n "${function}" ]; then + "${function}" "${@}" + fi + # context / shell + else + rwx_self_init + fi +} + # ╭──────┬─────╮ # │ main │ run │ # ╰──────┴─────╯ From b342a2c9e17ed1e9ae2366d779cd605a37033b35 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Tue, 8 Jul 2025 01:12:02 +0200 Subject: [PATCH 06/11] main/source --- sh/main.sh | 55 +++++++++++++++++++++++++++--------------------------- 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/sh/main.sh b/sh/main.sh index dd3628c..0476b0b 100755 --- a/sh/main.sh +++ b/sh/main.sh @@ -37,33 +37,6 @@ RWX_SELF_USER="${HOME}/${RWX_SELF_NAME}" # path to the entrypoint main file of the project RWX_MAIN_PATH="${RWX_ROOT_SYSTEM}/${RWX_MAIN_NAME}" -# ╭──────┬────────╮ -# │ main │ source │ -# ╰──────┴────────╯ - -# source code from file path -rwx_source() { - local root="${1}" - [ -d "${root}" ] || - return 1 - local file="${2}" - local count module modules - count=0 - __rwx_log "" \ - ". ${root}" - 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 < cat rwx_cache() { local root="${1}" local module="${2}" From 19249747c0b88dc0f1757a483387b12d72ac2cd1 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Tue, 8 Jul 2025 01:13:06 +0200 Subject: [PATCH 07/11] main/log --- sh/main.sh | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/sh/main.sh b/sh/main.sh index 0476b0b..b368970 100755 --- a/sh/main.sh +++ b/sh/main.sh @@ -37,20 +37,6 @@ RWX_SELF_USER="${HOME}/${RWX_SELF_NAME}" # path to the entrypoint main file of the project RWX_MAIN_PATH="${RWX_ROOT_SYSTEM}/${RWX_MAIN_NAME}" -# ╭──────┬─────╮ -# │ main │ log │ -# ╰──────┴─────╯ - -__rwx_log() { - if rwx_shell_interactive; then - [ ${#} -gt 0 ] || set -- "" - local line - for line in "${@}"; do - echo "${line}" - done - fi -} - # ╭──────┬───────╮ # │ main │ shell │ # ╰──────┴───────╯ @@ -92,6 +78,20 @@ rwx_find_shell() { ################################################################################ +# ╭──────┬─────╮ +# │ main │ log │ +# ╰──────┴─────╯ + +__rwx_log() { + if rwx_shell_interactive; then + [ ${#} -gt 0 ] || set -- "" + local line + for line in "${@}"; do + echo "${line}" + done + fi +} + # ╭──────┬────────╮ # │ main │ source │ # ╰──────┴────────╯ From aadfe212c2e4d4ecbf52464f1c15064939ccae18 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Tue, 8 Jul 2025 01:15:21 +0200 Subject: [PATCH 08/11] main/shell --- sh/main.sh | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/sh/main.sh b/sh/main.sh index b368970..6a70831 100755 --- a/sh/main.sh +++ b/sh/main.sh @@ -37,18 +37,6 @@ RWX_SELF_USER="${HOME}/${RWX_SELF_NAME}" # path to the entrypoint main file of the project RWX_MAIN_PATH="${RWX_ROOT_SYSTEM}/${RWX_MAIN_NAME}" -# ╭──────┬───────╮ -# │ main │ shell │ -# ╰──────┴───────╯ - -# test if active shell is in interactive mode -rwx_shell_interactive() { - case "${-}" in - *i*) ;; - *) return 1 ;; - esac -} - # ╭──────┬──────╮ # │ main │ find │ # ╰──────┴──────╯ @@ -78,6 +66,18 @@ rwx_find_shell() { ################################################################################ +# ╭──────┬───────╮ +# │ main │ shell │ +# ╰──────┴───────╯ + +# test if active shell is in interactive mode +rwx_shell_interactive() { + case "${-}" in + *i*) ;; + *) return 1 ;; + esac +} + # ╭──────┬─────╮ # │ main │ log │ # ╰──────┴─────╯ From ff3716148a8e1a0c5e180ecaae1fbd13e4d9422a Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Tue, 8 Jul 2025 01:20:36 +0200 Subject: [PATCH 09/11] find,sort --- sh/main.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sh/main.sh b/sh/main.sh index 6a70831..62a5bfc 100755 --- a/sh/main.sh +++ b/sh/main.sh @@ -42,6 +42,8 @@ RWX_MAIN_PATH="${RWX_ROOT_SYSTEM}/${RWX_MAIN_NAME}" # ╰──────┴──────╯ # find directory’s files by extension +#> find +#> sort rwx_find_extension() { local extension="${1}" local root="${2}" @@ -64,8 +66,6 @@ rwx_find_shell() { rwx_find_extension "sh" "${@}" } -################################################################################ - # ╭──────┬───────╮ # │ main │ shell │ # ╰──────┴───────╯ From b45449421e3a22cc600366f10a9ca1f2e525f288 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Tue, 8 Jul 2025 01:25:22 +0200 Subject: [PATCH 10/11] test/commands --- sh/test.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/sh/test.sh b/sh/test.sh index 4f4a557..ad17c22 100644 --- a/sh/test.sh +++ b/sh/test.sh @@ -21,7 +21,8 @@ rwx_test_code() { "variables" \ "functions" \ "aliases" \ - "aliases_functions" + "aliases_functions" \ + "commands" rwx_code for items in "${@}"; do echo @@ -46,7 +47,9 @@ rwx_test_doc() { "rwx_cache" \ \ "alias/batcat" \ - "b" + "b" \ + \ + "rwx_install" for item in "${@}"; do echo rwx_code_doc "${item}" From 091c9339f70b428eab746f315648c9e099ef7473 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Tue, 8 Jul 2025 01:43:30 +0200 Subject: [PATCH 11/11] code/command --- sh/code.awk | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/sh/code.awk b/sh/code.awk index efada06..fba6da4 100644 --- a/sh/code.awk +++ b/sh/code.awk @@ -41,6 +41,7 @@ BEGIN { RE_VARIABLE = RE_BEGIN RE_VAR RE_SET RE_END alias = 0 + command = 0 f = "" reset() module = 0 @@ -97,7 +98,7 @@ BEGIN { } else if (match($0, RE_COMMAND, m)) { append("/ " m[1]) if (m[1] == target) { - alias = 1 + command = 1 } # set } else if (match($0, RE_CONSTANT, m)) { @@ -124,6 +125,9 @@ BEGIN { if (alias) { print "= " target output(f, "function") + } else if (command) { + print "/ " target + output(f, "function") } else if (f == target) { output(f, "function") } else {