diff --git a/sh/code.sh b/sh/code.sh index de4b331..7eede91 100644 --- a/sh/code.sh +++ b/sh/code.sh @@ -181,3 +181,34 @@ rwx_code_parse() { --assign action="${action}" \ "${_rwx_code_awk}" } + +# ╭──────┬──────╮ +# │ code │ main │ +# ╰──────┴──────╯ + +rwx_code_main() { + # source user root + rwx_source "${RWX_SELF_USER}" + # load code cache + rwx_code_load + # context / command + 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 + # find the matching function + function="$(rwx_code_alias_function "${command}")" + if [ -n "${function}" ]; then + "${function}" "${@}" + fi + # context / shell + else + rwx_self_init + fi +} diff --git a/sh/main.sh b/sh/main.sh index f9241ac..d75515f 100755 --- a/sh/main.sh +++ b/sh/main.sh @@ -3,15 +3,6 @@ # │ main │ # ╰──────╯ # main module -# * builtins -# * echo -# * printf -# * read -# * binaries -# * awk -# * cat -# * find -# * sed # ╭──────┬───────────╮ # │ main │ constants │ @@ -29,6 +20,7 @@ RWX_SELF_NAME="rwx" # cache of all sourced code modules _rwx_code="" +# TODO variablize # system root directory of the project RWX_ROOT_SYSTEM="/usr/local/lib/${RWX_SELF_NAME}" # user root directory of the project @@ -145,6 +137,7 @@ ${text} # ╰──────┴──────╯ # run initial steps +#< code rwx_main() { # cache main rwx_cache "${RWX_ROOT_SYSTEM}" "${RWX_MAIN_NAME}" @@ -153,30 +146,8 @@ rwx_main() { __rwx_log "Not a directory: ${RWX_ROOT_SYSTEM}" return 1 fi - # source user root - rwx_source "${RWX_SELF_USER}" - # load code cache - rwx_code_load - # context / command - 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 - # find the matching function - function="$(rwx_code_alias_function "${command}")" - if [ -n "${function}" ]; then - "${function}" "${@}" - fi - # context / shell - else - rwx_self_init - fi + # run code main function + rwx_code_main } # ╭──────┬─────╮