diff --git a/sh/alias/git.sh b/sh/alias/git.sh index fe5380a..35402d9 100644 --- a/sh/alias/git.sh +++ b/sh/alias/git.sh @@ -1,10 +1,8 @@ RWX_GIT_LOG_FORMAT="\ %C(auto)%h%d S %C(red)%GS -A %C(green)%an %ae - %C(green)%ai -C %C(blue)%cn %ce - %C(blue)%ci +A %C(green)%ai %an %ae +C %C(blue)%ci %cn %ce %B" # add to index diff --git a/sh/file.sh b/sh/file.sh new file mode 100644 index 0000000..becca76 --- /dev/null +++ b/sh/file.sh @@ -0,0 +1,26 @@ +# ╭──────╮ +# │ file │ +# ╰──────╯ + +rwx_file_append() { + local file="${1}" + local text="${2}" + if [ -n "${file}" ]; then + printf "%s" "${text}" >>"${file}" + fi +} + +rwx_file_empty() { + local file="${1}" + if [ -n "${file}" ]; then + rwx_file_write "${file}" "" + fi +} + +rwx_file_write() { + local file="${1}" + local text="${2}" + if [ -n "${file}" ]; then + printf "%s" "${text}" >"${file}" + fi +} diff --git a/sh/log/log.sh b/sh/log/log.sh index b921d45..a3013e8 100644 --- a/sh/log/log.sh +++ b/sh/log/log.sh @@ -1,3 +1,11 @@ +# ╭─────╮ +# │ log │ +# ╰─────╯ + +# ╭─────┬───────────╮ +# │ log │ constants │ +# ╰─────┴───────────╯ + RWX_LOG_LEVEL_FATAL=0 RWX_LOG_LEVEL_ERROR=1 RWX_LOG_LEVEL_WARN=2 @@ -5,8 +13,16 @@ RWX_LOG_LEVEL_INFO=3 RWX_LOG_LEVEL_DEBUG=4 RWX_LOG_LEVEL_TRACE=5 +# ╭─────┬───────────╮ +# │ log │ variables │ +# ╰─────┴───────────╯ + RWX_LOG_LEVEL=${RWX_LOG_LEVEL_INFO} +# ╭─────┬─────╮ +# │ log │ log │ +# ╰─────┴─────╯ + rwx_log() { rwx_log_info "${@}"; } rwx_log_debug() { diff --git a/sh/main.sh b/sh/main.sh index 40fbf17..63ca6bf 100755 --- a/sh/main.sh +++ b/sh/main.sh @@ -1,5 +1,9 @@ #! /usr/bin/env sh +# ╭──────╮ +# │ main │ +# ╰──────╯ + # ╭──────┬───────────╮ # │ main │ constants │ # ╰──────┴───────────╯ @@ -27,16 +31,50 @@ RWX_SELF_USER="${HOME}/${RWX_SELF_NAME}" RWX_MAIN_PATH="${RWX_ROOT_SYSTEM}/${RWX_MAIN_NAME}" -# ╭──────┬───────╮ -# │ main │ shell │ -# ╰──────┴───────╯ +# ╭──────┬──────╮ +# │ main │ main │ +# ╰──────┴──────╯ -# test if active shell is in interactive mode -rwx_shell_interactive() { - case "${-}" in - *i*) ;; - *) return 1 ;; - esac +# run initial steps +rwx_main() { + # source system root + if ! rwx_source "${RWX_ROOT_SYSTEM}"; then + __rwx_log "Not a directory: ${RWX_ROOT_SYSTEM}" + return 1 + fi + # source user root + rwx_source "${RWX_SELF_USER}" + # context / command + if [ -n "${RWX_COMMAND_NAME}" ]; then + "${RWX_SELF_COMMAND}${RWX_COMMAND_NAME}" "${@}" + # context / shell + else + rwx_self_init + fi +} + +# ╭──────┬────────╮ +# │ main │ source │ +# ╰──────┴────────╯ + +# source code from file path +rwx_source() { + local path="${1}" + [ -d "${path}" ] || + return 1 + local count module + count=0 + __rwx_log "" \ + ". ${path}" + rwx_ifs_set + for module in $(rwx_find_shell "${path}" "${RWX_MAIN_NAME}"); do + count=$((count + 1)) + __rwx_log "$(printf "%02d" "${count}") ${module%.sh}" + module="${path}/${module}" + # shellcheck disable=SC1090 + . "${module}" + done + rwx_ifs_unset } # ╭──────┬─────╮ @@ -53,6 +91,35 @@ __rwx_log() { fi } +# ╭──────┬───────╮ +# │ main │ shell │ +# ╰──────┴───────╯ + +# test if active shell is in interactive mode +rwx_shell_interactive() { + case "${-}" in + *i*) ;; + *) return 1 ;; + esac +} + +# ╭──────┬─────╮ +# │ main │ ifs │ +# ╰──────┴─────╯ + +# set internal field separator to line feed +rwx_ifs_set() { + _RWX_IFS="${IFS}" + IFS=" +" +} + +# unset internal field separator +rwx_ifs_unset() { + IFS="${_RWX_IFS}" + unset RWX_IFS +} + # ╭──────┬──────╮ # │ main │ find │ # ╰──────┴──────╯ @@ -81,67 +148,8 @@ rwx_find_shell() { } # ╭──────┬─────╮ -# │ main │ ifs │ +# │ main │ run │ # ╰──────┴─────╯ -# set internal field separator to line feed -rwx_ifs_set() { - _RWX_IFS="${IFS}" - IFS=" -" -} - -# unset internal field separator -rwx_ifs_unset() { - IFS="${_RWX_IFS}" - unset RWX_IFS -} - -# ╭──────┬────────╮ -# │ main │ source │ -# ╰──────┴────────╯ - -# source code from file path -rwx_source() { - local path="${1}" - [ -d "${path}" ] || - return 1 - local count module - count=0 - __rwx_log "" \ - ". ${path}" - rwx_ifs_set - for module in $(rwx_find_shell "${path}" "${RWX_MAIN_NAME}"); do - count=$((count + 1)) - __rwx_log "$(printf "%02d" "${count}") ${module%.sh}" - module="${path}/${module}" - # shellcheck disable=SC1090 - . "${module}" - done - rwx_ifs_unset -} - -# ╭──────╮ -# │ main │ -# ╰──────╯ - -# run initial steps -rwx_main() { - # system root - if ! rwx_source "${RWX_ROOT_SYSTEM}"; then - __rwx_log "Not a directory: ${RWX_ROOT_SYSTEM}" - return 1 - fi - # user root - rwx_source "${RWX_SELF_USER}" - # context / command - if [ -n "${RWX_COMMAND_NAME}" ]; then - "${RWX_SELF_COMMAND}${RWX_COMMAND_NAME}" "${@}" - # context / shell - else - rwx_self_init - fi -} - # run main function rwx_main "${@}" diff --git a/sh/tmux.sh b/sh/tmux.sh index 0294e7f..a29ec26 100644 --- a/sh/tmux.sh +++ b/sh/tmux.sh @@ -1,3 +1,7 @@ +# ╭──────╮ +# │ tmux │ +# ╰──────╯ + # ╭──────┬───────╮ # │ tmux │ setup │ # ╰──────┴───────╯ diff --git a/sh/util.sh b/sh/util.sh index cbcd67a..a3c53bf 100644 --- a/sh/util.sh +++ b/sh/util.sh @@ -1,25 +1,6 @@ -rwx_file_append() { - local file="${1}" - local text="${2}" - if [ -n "${file}" ]; then - printf "%s" "${text}" >>"${file}" - fi -} - -rwx_file_empty() { - local file="${1}" - if [ -n "${file}" ]; then - rwx_file_write "${file}" "" - fi -} - -rwx_file_write() { - local file="${1}" - local text="${2}" - if [ -n "${file}" ]; then - printf "%s" "${text}" >"${file}" - fi -} +# ╭──────╮ +# │ util │ +# ╰──────╯ rwx_link() { local link="${1}"