diff --git a/sh/core/code.sh b/sh/core/code.sh index f8748c0..af9962f 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 - else + if [ -n "${command}" ]; then 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 } diff --git a/sh/log/log.sh b/sh/log/log.sh index eddf92c..f5e13b1 100644 --- a/sh/log/log.sh +++ b/sh/log/log.sh @@ -69,16 +69,6 @@ rwx_log_warn() { fi } -# TODO simplify - -_rwx_main_log() { - [ ${#} -gt 0 ] || set -- "" - local line - for line in "${@}"; do - echo "${line}" - done -} - _rwx_log() { local prefix="${1}" shift diff --git a/sh/main.sh b/sh/main.sh index d6cc20c..3aa62c2 100755 --- a/sh/main.sh +++ b/sh/main.sh @@ -43,6 +43,32 @@ rwx_main_find() { sort } +# ╭──────┬───────╮ +# │ main │ shell │ +# ╰──────┴───────╯ + +# test if active shell is in interactive mode +rwx_main_interactive() { + case "${-}" in + *i*) ;; + *) return 1 ;; + 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 │ # ╰──────┴──────╯ diff --git a/sh/shell/0.sh b/sh/shell/0.sh index f93f312..92d5aaa 100644 --- a/sh/shell/0.sh +++ b/sh/shell/0.sh @@ -38,22 +38,10 @@ 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=1 - # ╭───────┬───────────╮ # │ 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 @@ -173,12 +161,6 @@ rwx_shell_exit() { # ╰───────┴──────╯ rwx_shell_main() { - # set current shell interactive mode - case "${-}" in - *"i"*) rwx_shell_interactive=0 ;; - *) ;; - esac - # configure shell rwx_shell_configure }