From a7b310b6673fccbfcde3f22c6186ef87963232ff Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Mon, 7 Jul 2025 05:22:40 +0200 Subject: [PATCH 1/3] =?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, 1 insertion(+), 2 deletions(-) diff --git a/sh/main.sh b/sh/main.sh index d96d776..8339831 100755 --- a/sh/main.sh +++ b/sh/main.sh @@ -26,13 +26,12 @@ RWX_SELF_NAME="rwx" # │ main │ variables │ # ╰──────┴───────────╯ -RWX_COMMAND_ARGUMENT="${0}" # currently running shell name RWX_SHELL="$(cat "/proc/${$}/comm")" # command name used to run # (stripped from hyphen interactive flag) -RWX_COMMAND_NAME="$(basename "${RWX_COMMAND_ARGUMENT}" | sed "s|^-||")" +RWX_COMMAND_NAME="$(basename "${0}" | sed "s|^-||")" case "${RWX_COMMAND_NAME}" in "bash" | "dash" | "sh") unset RWX_COMMAND_NAME ;; *) ;; From 2480e490be1e8536c8ce19248aba69119e33611d Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Mon, 7 Jul 2025 05:33:43 +0200 Subject: [PATCH 2/3] main/command --- sh/main.sh | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/sh/main.sh b/sh/main.sh index 8339831..470cf72 100755 --- a/sh/main.sh +++ b/sh/main.sh @@ -29,13 +29,6 @@ RWX_SELF_NAME="rwx" # currently running shell name RWX_SHELL="$(cat "/proc/${$}/comm")" -# command name used to run -# (stripped from hyphen interactive flag) -RWX_COMMAND_NAME="$(basename "${0}" | sed "s|^-||")" -case "${RWX_COMMAND_NAME}" in -"bash" | "dash" | "sh") unset RWX_COMMAND_NAME ;; -*) ;; -esac # system root directory of the project RWX_ROOT_SYSTEM="/usr/local/lib/${RWX_SELF_NAME}" # user root directory of the project @@ -62,9 +55,18 @@ rwx_main() { # load code cache rwx_code_load # context / command - if [ -n "${RWX_COMMAND_NAME}" ]; then + 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 - function="$(rwx_code_alias_function "${RWX_COMMAND_NAME}")" + # find the matching function + function="$(rwx_code_alias_function "${command}")" if [ -n "${function}" ]; then "${function}" "${@}" fi From dd90da8a821281794e30fd82d1600e93723f29e7 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Mon, 7 Jul 2025 05:48:43 +0200 Subject: [PATCH 3/3] shell/standalone --- sh/alias/shell.sh | 29 ------------------------- sh/main.sh | 3 --- sh/shell.sh | 54 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 32 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 d6f5801..0000000 --- a/sh/alias/shell.sh +++ /dev/null @@ -1,29 +0,0 @@ -# shorten alias -a() { - alias \ - "${@}" -} - -# swap directory (current ↔ previous) -sd() { - cd \ - - || - return -} - -# exit terminal -x() { - exit \ - "${@}" -} - -[ "${RWX_SHELL}" = "bash" ] || return - -# shellcheck disable=SC3033 -..() { - cd .. -} -# shellcheck disable=SC3033 -...() { - cd ../.. -} 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.sh b/sh/shell.sh index 7e56658..8400fd2 100644 --- a/sh/shell.sh +++ b/sh/shell.sh @@ -1,3 +1,7 @@ +# ╭───────╮ +# │ shell │ +# ╰───────╯ + _rwx_shell_color() { local code="${1}" case "${RWX_SHELL}" in @@ -19,6 +23,11 @@ _rwx_shell_color() { ;; esac } + +# ╭───────┬───────────╮ +# │ shell │ constants │ +# ╰───────┴───────────╯ + RWX_COLOR_BROWN="$(_rwx_shell_color 33)" RWX_COLOR_CYAN="$(_rwx_shell_color 36)" RWX_COLOR_DEFAULT="$(_rwx_shell_color)" @@ -26,6 +35,17 @@ RWX_COLOR_GREEN="$(_rwx_shell_color 31)" RWX_COLOR_MAGENTA="$(_rwx_shell_color 35)" RWX_COLOR_RED="$(_rwx_shell_color 32)" +# ╭───────┬───────────╮ +# │ shell │ variables │ +# ╰───────┴───────────╯ + +# currently running shell name +RWX_SHELL="$(cat "/proc/${$}/comm")" + +# ╭───────┬───────────╮ +# │ shell │ functions │ +# ╰───────┴───────────╯ + rwx_shell_configure() { [ -n "${ENV}" ] || ENV="${RWX_MAIN_PATH}" export ENV @@ -114,3 +134,37 @@ rwx_shell_prompt() { # print printf "%b" "${view}" } + +# ╭───────┬───────────╮ +# │ shell │ shortcuts │ +# ╰───────┴───────────╯ + +# shorten alias +a() { + alias \ + "${@}" +} + +# swap directory (current ↔ previous) +sd() { + cd \ + - || + return +} + +# exit terminal +x() { + exit \ + "${@}" +} + +[ "${RWX_SHELL}" = "bash" ] || return + +# shellcheck disable=SC3033 +..() { + cd .. +} +# shellcheck disable=SC3033 +...() { + cd ../.. +}