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 } diff --git a/sh/log/log.sh b/sh/log/log.sh index f5e13b1..eddf92c 100644 --- a/sh/log/log.sh +++ b/sh/log/log.sh @@ -69,6 +69,16 @@ 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 3aa62c2..d6cc20c 100755 --- a/sh/main.sh +++ b/sh/main.sh @@ -43,32 +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 │ 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 92d5aaa..f93f312 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=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 @@ -161,6 +173,12 @@ rwx_shell_exit() { # ╰───────┴──────╯ rwx_shell_main() { + # set current shell interactive mode + case "${-}" in + *"i"*) rwx_shell_interactive=0 ;; + *) ;; + esac + # configure shell rwx_shell_configure }