From 5225d6a1ae26f49941d564d278fd54c3d7694a1b Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Thu, 10 Jul 2025 04:39:14 +0200 Subject: [PATCH] shell/context,help --- sh/core/code.sh | 33 --------------------------------- sh/shell/0.sh | 29 +++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 33 deletions(-) diff --git a/sh/core/code.sh b/sh/core/code.sh index 28f5c06..356e757 100644 --- a/sh/core/code.sh +++ b/sh/core/code.sh @@ -57,18 +57,6 @@ rwx_code_cache_user() { echo "${rwx_code_cache_user}" } -# ╭──────┬──────╮ -# │ code │ help │ -# ╰──────┴──────╯ - -# output help message -rwx_code_help() { - rwx_log "" \ - "rwx_… = functions" \ - " a__… = aliases" \ - " u__… = user" -} - # ╭──────┬─────────╮ # │ code │ install │ # ╰──────┴─────────╯ @@ -296,25 +284,4 @@ ${rwx_code_modules_user} EOF # load code cache rwx_code_load - # context / shell - if rwx_shell_interactive; then - # display help - rwx_code_help - # context / command - else - local command - local function - # command name used to run - # (stripped from hyphen interactive flag) - command="$(basename "${0}" | sed "s|^-||")" - case "${command}" in - "bash" | "dash" | "sh") unset command ;; - *) ;; - esac - # find the matching function - function="$(rwx_code_command_function "${command}")" - if [ -n "${function}" ]; then - "${function}" "${@}" - fi - fi } diff --git a/sh/shell/0.sh b/sh/shell/0.sh index 6eb5989..b0e5027 100644 --- a/sh/shell/0.sh +++ b/sh/shell/0.sh @@ -49,6 +49,14 @@ rwx_shell_interactive=1 # │ shell │ functions │ # ╰───────┴───────────╯ +# output help message +rwx_shell_help() { + rwx_log "" \ + "rwx_… = functions" \ + " a__… = aliases" \ + " u__… = user" +} + # return current shell interactive mode rwx_shell_interactive() { return "${rwx_shell_interactive}" @@ -180,4 +188,25 @@ rwx_shell_main() { esac # configure shell rwx_shell_configure + # context / shell + if rwx_shell_interactive; then + # display help + rwx_shell_help + # context / command + else + local command + local function + # command name used to run + # (stripped from hyphen interactive flag) + command="$(basename "${0}" | sed "s|^-||")" + case "${command}" in + "bash" | "dash" | "sh") unset command ;; + *) ;; + esac + # find the matching function + function="$(rwx_code_command_function "${command}")" + if [ -n "${function}" ]; then + "${function}" "${@}" + fi + fi }