From 60ccba2fd53c9c9e6403716483337f34a69002d1 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Mon, 7 Jul 2025 03:47:55 +0200 Subject: [PATCH 1/6] =?UTF-8?q?=E2=88=92self/commands?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sh/self.sh | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/sh/self.sh b/sh/self.sh index 0752da9..98d79cf 100644 --- a/sh/self.sh +++ b/sh/self.sh @@ -1,19 +1,6 @@ -# self -# module - -# ╭──────┬──────────╮ -# │ self │ commands │ -# ╰──────┴──────────╯ - -# get commands from root -rwx_self_commands() { - grep \ - --directories "recurse" \ - --no-filename \ - "^${RWX_SELF_COMMAND}" "${RWX_ROOT_SYSTEM}" | - cut --delimiter "(" --fields 1 | - sed "s|^${RWX_SELF_COMMAND}||" -} +# ╭──────╮ +# │ self │ +# ╰──────╯ # ╭──────┬──────╮ # │ self │ help │ @@ -44,8 +31,8 @@ rwx_self_init() { # │ self │ install │ # ╰──────┴─────────╯ -_rwx_cmd_rwx_install() { rwx_self_install "${@}"; } -rwx_self_install() { +#= rwx_install +rwx_code_install() { local target="${1}" local command file name root # code From e57b963f25c44ac9fbbd692b14689e291abc4926 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Mon, 7 Jul 2025 03:51:14 +0200 Subject: [PATCH 2/6] code/install --- sh/code.sh | 37 +++++++++++++++++++++++++++++++++++++ sh/self.sh | 37 ------------------------------------- 2 files changed, 37 insertions(+), 37 deletions(-) diff --git a/sh/code.sh b/sh/code.sh index e5a898b..a016377 100644 --- a/sh/code.sh +++ b/sh/code.sh @@ -19,6 +19,43 @@ _rwx_code_functions="" # cache for code variables _rwx_code_variables="" +# ╭──────┬─────────╮ +# │ code │ install │ +# ╰──────┴─────────╯ + +#= rwx_install +rwx_code_install() { + local target="${1}" + local command file name root + # code + if [ -n "${target}" ]; then + root="${target}${RWX_ROOT_SYSTEM}" + rwx_remove "${root}" + cp --recursive "${RWX_ROOT_SYSTEM}" "${root}" + fi + # commands + root="${target}/usr/local/bin" + name="${RWX_SELF_NAME}.sh" + file="${root}/${name}" + rwx_remove "${file}" + rwx_link "${file}" "${RWX_MAIN_PATH}" + for command in $(rwx_self_commands); do + file="${root}/${command}" + rwx_remove "${file}" + rwx_link "${file}" "${name}" + done + # sh + file="${target}/etc/profile.d/${RWX_SELF_NAME}.sh" + rwx_remove "${file}" + rwx_file_write "${file}" "\ +export ENV=\"${RWX_MAIN_PATH}\" +" + # bash + file="${target}/etc/bash.bashrc" + rwx_remove "${file}" + rwx_link "${file}" "${RWX_MAIN_PATH}" +} + # ╭──────┬───────╮ # │ code │ parts │ # ╰──────┴───────╯ diff --git a/sh/self.sh b/sh/self.sh index 98d79cf..968c44b 100644 --- a/sh/self.sh +++ b/sh/self.sh @@ -27,43 +27,6 @@ rwx_self_init() { fi } -# ╭──────┬─────────╮ -# │ self │ install │ -# ╰──────┴─────────╯ - -#= rwx_install -rwx_code_install() { - local target="${1}" - local command file name root - # code - if [ -n "${target}" ]; then - root="${target}${RWX_ROOT_SYSTEM}" - rwx_remove "${root}" - cp --recursive "${RWX_ROOT_SYSTEM}" "${root}" - fi - # commands - root="${target}/usr/local/bin" - name="${RWX_SELF_NAME}.sh" - file="${root}/${name}" - rwx_remove "${file}" - rwx_link "${file}" "${RWX_MAIN_PATH}" - for command in $(rwx_self_commands); do - file="${root}/${command}" - rwx_remove "${file}" - rwx_link "${file}" "${name}" - done - # sh - file="${target}/etc/profile.d/${RWX_SELF_NAME}.sh" - rwx_remove "${file}" - rwx_file_write "${file}" "\ -export ENV=\"${RWX_MAIN_PATH}\" -" - # bash - file="${target}/etc/bash.bashrc" - rwx_remove "${file}" - rwx_link "${file}" "${RWX_MAIN_PATH}" -} - # ╭──────┬────────╮ # │ self │ subset │ # ╰──────┴────────╯ From 47ff6043d5aaafeb222ecb3e93a489961657835b Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Mon, 7 Jul 2025 04:02:44 +0200 Subject: [PATCH 3/6] install/while --- sh/code.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/sh/code.sh b/sh/code.sh index a016377..62f28a2 100644 --- a/sh/code.sh +++ b/sh/code.sh @@ -39,11 +39,13 @@ rwx_code_install() { file="${root}/${name}" rwx_remove "${file}" rwx_link "${file}" "${RWX_MAIN_PATH}" - for command in $(rwx_self_commands); do + while IFS= read -r command; do file="${root}/${command}" rwx_remove "${file}" rwx_link "${file}" "${name}" - done + done < Date: Mon, 7 Jul 2025 04:23:21 +0200 Subject: [PATCH 4/6] alias/function --- sh/code.sh | 15 +++++++++++++++ sh/main.sh | 1 + 2 files changed, 16 insertions(+) diff --git a/sh/code.sh b/sh/code.sh index 62f28a2..76487b9 100644 --- a/sh/code.sh +++ b/sh/code.sh @@ -79,6 +79,21 @@ rwx_code_aliases() { echo "${_rwx_code_aliases}" } +# find aliased function +rwx_code_alias_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: Mon, 7 Jul 2025 04:29:55 +0200 Subject: [PATCH 5/6] main/function --- sh/main.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/sh/main.sh b/sh/main.sh index 8bc54e6..ea62483 100755 --- a/sh/main.sh +++ b/sh/main.sh @@ -67,8 +67,11 @@ rwx_main() { rwx_code_load # context / command if [ -n "${RWX_COMMAND_NAME}" ]; then - # TODO - "${RWX_SELF_COMMAND}${RWX_COMMAND_NAME}" "${@}" + local function + function="$(rwx_code_alias_function "${RWX_COMMAND_NAME}")" + if [ -n "${function}" ]; then + "${function}" "${@}" + fi # context / shell else rwx_self_init From 62b3a9264b150f7040d5b53690d4acf349b840b9 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Mon, 7 Jul 2025 04:34:57 +0200 Subject: [PATCH 6/6] =?UTF-8?q?=E2=88=92useless?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sh/main.sh | 3 --- 1 file changed, 3 deletions(-) diff --git a/sh/main.sh b/sh/main.sh index ea62483..d96d776 100755 --- a/sh/main.sh +++ b/sh/main.sh @@ -22,9 +22,6 @@ RWX_MAIN_NAME="main.sh" # name of the project itself RWX_SELF_NAME="rwx" -# prefix for command functions -RWX_SELF_COMMAND="_${RWX_SELF_NAME}_cmd_" - # ╭──────┬───────────╮ # │ main │ variables │ # ╰──────┴───────────╯