From a429cad22cfa67b435f6520951775fdf5376c307 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Wed, 9 Jul 2025 19:07:50 +0200 Subject: [PATCH 1/5] =?UTF-8?q?main=20=E2=86=92=20log?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sh/log/log.sh | 12 ++++++++++++ sh/main.sh | 14 -------------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/sh/log/log.sh b/sh/log/log.sh index f5e13b1..a7c9c36 100644 --- a/sh/log/log.sh +++ b/sh/log/log.sh @@ -69,6 +69,18 @@ rwx_log_warn() { fi } +# TODO simplify + +_rwx_main_log() { + if rwx_main_interactive; then + [ ${#} -gt 0 ] || set -- "" + local line + for line in "${@}"; do + echo "${line}" + done + fi +} + _rwx_log() { local prefix="${1}" shift diff --git a/sh/main.sh b/sh/main.sh index 3aa62c2..a7d1781 100755 --- a/sh/main.sh +++ b/sh/main.sh @@ -55,20 +55,6 @@ rwx_main_interactive() { esac } -# ╭──────┬─────╮ -# │ main │ log │ -# ╰──────┴─────╯ - -_rwx_main_log() { - if rwx_main_interactive; then - [ ${#} -gt 0 ] || set -- "" - local line - for line in "${@}"; do - echo "${line}" - done - fi -} - # ╭──────┬──────╮ # │ main │ main │ # ╰──────┴──────╯ From 84c26d227374089fa41bf350af00cfa2069dc930 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Wed, 9 Jul 2025 20:07:33 +0200 Subject: [PATCH 2/5] =?UTF-8?q?main=20=E2=86=92=20shell?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sh/main.sh | 12 ------------ sh/shell/0.sh | 18 ++++++++++++++++++ 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/sh/main.sh b/sh/main.sh index a7d1781..d6cc20c 100755 --- a/sh/main.sh +++ b/sh/main.sh @@ -43,18 +43,6 @@ rwx_main_find() { sort } -# ╭──────┬───────╮ -# │ main │ shell │ -# ╰──────┴───────╯ - -# test if active shell is in interactive mode -rwx_main_interactive() { - case "${-}" in - *i*) ;; - *) return 1 ;; - esac -} - # ╭──────┬──────╮ # │ main │ main │ # ╰──────┴──────╯ diff --git a/sh/shell/0.sh b/sh/shell/0.sh index 92d5aaa..33a7745 100644 --- a/sh/shell/0.sh +++ b/sh/shell/0.sh @@ -38,10 +38,22 @@ RWX_COLOR_GREEN="$(_rwx_shell_color 31)" RWX_COLOR_MAGENTA="$(_rwx_shell_color 35)" RWX_COLOR_RED="$(_rwx_shell_color 32)" +# ╭───────┬───────────╮ +# │ shell │ variables │ +# ╰───────┴───────────╯ + +# current shell interactive mode +rwx_shell_interactive=0 + # ╭───────┬───────────╮ # │ shell │ functions │ # ╰───────┴───────────╯ +# return current shell interactive mode +rwx_shell_interactive() { + return "${rwx_shell_interactive}" +} + rwx_shell_configure() { [ -n "${ENV}" ] || ENV="${rwx_code_main}" export ENV @@ -161,6 +173,12 @@ rwx_shell_exit() { # ╰───────┴──────╯ rwx_shell_main() { + # set current shell interactive mode + case "${-}" in + *"i"*) rwx_shell_interactive=1 ;; + *) ;; + esac + # configure shell rwx_shell_configure } From 8ed00e1788abdd06d020b354681309285f2d3687 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Wed, 9 Jul 2025 20:12:46 +0200 Subject: [PATCH 3/5] =?UTF-8?q?=E2=88=92useless?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sh/log/log.sh | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/sh/log/log.sh b/sh/log/log.sh index a7c9c36..eddf92c 100644 --- a/sh/log/log.sh +++ b/sh/log/log.sh @@ -72,13 +72,11 @@ rwx_log_warn() { # TODO simplify _rwx_main_log() { - if rwx_main_interactive; then - [ ${#} -gt 0 ] || set -- "" - local line - for line in "${@}"; do - echo "${line}" - done - fi + [ ${#} -gt 0 ] || set -- "" + local line + for line in "${@}"; do + echo "${line}" + done } _rwx_log() { From b1fc5bf235c94d531c922882f5c30995f0d0d1ab Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Wed, 9 Jul 2025 20:42:41 +0200 Subject: [PATCH 4/5] context/interactive --- sh/core/code.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/sh/core/code.sh b/sh/core/code.sh index af9962f..f8748c0 100644 --- a/sh/core/code.sh +++ b/sh/core/code.sh @@ -263,17 +263,17 @@ EOF "bash" | "dash" | "sh") unset command ;; *) ;; esac + # context / shell + if rwx_shell_interactive; then + # display help + rwx_code_help # context / command - if [ -n "${command}" ]; then + else local function # find the matching function function="$(rwx_code_command_function "${command}")" if [ -n "${function}" ]; then "${function}" "${@}" fi - # context / shell - else - # display help - rwx_code_help fi } From 449958091b0e5f3a15d8568487d46fda1d90fee2 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Wed, 9 Jul 2025 20:53:11 +0200 Subject: [PATCH 5/5] =?UTF-8?q?0=E2=86=941?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sh/shell/0.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sh/shell/0.sh b/sh/shell/0.sh index 33a7745..f93f312 100644 --- a/sh/shell/0.sh +++ b/sh/shell/0.sh @@ -43,7 +43,7 @@ RWX_COLOR_RED="$(_rwx_shell_color 32)" # ╰───────┴───────────╯ # current shell interactive mode -rwx_shell_interactive=0 +rwx_shell_interactive=1 # ╭───────┬───────────╮ # │ shell │ functions │ @@ -175,7 +175,7 @@ rwx_shell_exit() { rwx_shell_main() { # set current shell interactive mode case "${-}" in - *"i"*) rwx_shell_interactive=1 ;; + *"i"*) rwx_shell_interactive=0 ;; *) ;; esac # configure shell