diff --git a/sh/alias/shell.sh b/sh/alias/shell.sh new file mode 100644 index 0000000..f216c92 --- /dev/null +++ b/sh/alias/shell.sh @@ -0,0 +1,18 @@ +# shorten alias +a() { + alias \ + "${@}" +} + +# swap directory (current ↔ previous) +sd() { + cd \ + - || + return +} + +# exit terminal +x() { + exit \ + "${@}" +} diff --git a/sh/code.awk b/sh/code.awk index fba6da4..0d23127 100644 --- a/sh/code.awk +++ b/sh/code.awk @@ -32,7 +32,6 @@ BEGIN { RE_ALIAS = RE_BEGIN "#=" RE_SPACES RE_VAR RE_END RE_CLOSE = RE_BEGIN "}" RE_SPACES RE_END - RE_COMMAND = RE_BEGIN "#/" RE_SPACES RE_VAR RE_END RE_CONSTANT = RE_BEGIN RE_CONST RE_SET RE_END RE_DOC = RE_BEGIN RE_SPACES "#" RE_SPACE RE_ANY RE_END RE_FUNCTION = RE_BEGIN RE_VAR RE_FUNC RE_END @@ -41,7 +40,6 @@ BEGIN { RE_VARIABLE = RE_BEGIN RE_VAR RE_SET RE_END alias = 0 - command = 0 f = "" reset() module = 0 @@ -52,10 +50,6 @@ BEGIN { if (match($0, RE_ALIAS, m)) { print m[1] } - } else if (action == "commands") { - if (match($0, RE_COMMAND, m)) { - print m[1] - } } else if (action == "constants") { if (match($0, RE_CONSTANT, m)) { print m[1] @@ -95,11 +89,6 @@ BEGIN { if (m[1] == target) { alias = 1 } - } else if (match($0, RE_COMMAND, m)) { - append("/ " m[1]) - if (m[1] == target) { - command = 1 - } # set } else if (match($0, RE_CONSTANT, m)) { if (m[1] == target) { @@ -125,9 +114,6 @@ BEGIN { if (alias) { print "= " target output(f, "function") - } else if (command) { - print "/ " target - output(f, "function") } else if (f == target) { output(f, "function") } else { diff --git a/sh/code.sh b/sh/code.sh index de4b331..76487b9 100644 --- a/sh/code.sh +++ b/sh/code.sh @@ -12,8 +12,6 @@ _rwx_code_awk="$(cat "${RWX_ROOT_SYSTEM}/code.awk")" _rwx_code_aliases="" # cache for code aliases functions _rwx_code_aliases_functions="" -# cache for code commands -_rwx_code_commands="" # cache for code constants _rwx_code_constants="" # cache for code functions @@ -25,7 +23,7 @@ _rwx_code_variables="" # │ code │ install │ # ╰──────┴─────────╯ -#/ rwx_install +#= rwx_install rwx_code_install() { local target="${1}" local command file name root @@ -46,7 +44,7 @@ rwx_code_install() { rwx_remove "${file}" rwx_link "${file}" "${name}" done < find -#> sort -rwx_find_extension() { - local extension="${1}" - local root="${2}" - local file="${3}" - set -- \ - "${root}" \ - -name "*.${extension}" \ - -type "f" - [ -n "${file}" ] && - set -- "${@}" \ - -not \ - -name "${file}" - find "${@}" \ - -printf "%P\n" | - sort -} - -# find directory’s sh files -rwx_find_shell() { - rwx_find_extension "sh" "${@}" -} - -# ╭──────┬───────╮ -# │ main │ shell │ -# ╰──────┴───────╯ - -# test if active shell is in interactive mode -rwx_shell_interactive() { - case "${-}" in - *i*) ;; - *) return 1 ;; - esac -} - -# ╭──────┬─────╮ -# │ main │ log │ -# ╰──────┴─────╯ - -__rwx_log() { - if rwx_shell_interactive; then - [ ${#} -gt 0 ] || set -- "" - local line - for line in "${@}"; do - echo "${line}" - done - fi -} - -# ╭──────┬────────╮ -# │ main │ source │ -# ╰──────┴────────╯ - -# source code from file path -rwx_source() { - local root="${1}" - [ -d "${root}" ] || - return 1 - local file="${2}" - local count module modules - count=0 - __rwx_log "" \ - ". ${root}" - modules="$(rwx_find_shell "${root}" "${file}")" - while IFS= read -r module; do - count=$((count + 1)) - __rwx_log "$(printf "%02d" "${count}") ${module%.sh}" - # shellcheck disable=SC1090 - . "${root}/${module}" - # cache code - rwx_cache "${root}" "${module}" - done < cat -rwx_cache() { - local root="${1}" - local module="${2}" - local name="${module%.sh}" - local path="${root}/${module}" - local text - text="$(cat "${path}")" - # all source code - _rwx_code="${_rwx_code}\ -#. ${name} -${text} -" -} - # ╭──────┬──────╮ # │ main │ main │ # ╰──────┴──────╯ @@ -179,6 +76,109 @@ rwx_main() { fi } +# ╭──────┬───────╮ +# │ main │ cache │ +# ╰──────┴───────╯ + +# cache of all sourced code modules +_rwx_code="" + +# cache source code of a module +# inside a global code variable +rwx_cache() { + local root="${1}" + local module="${2}" + local name="${module%.sh}" + local path="${root}/${module}" + local text + text="$(cat "${path}")" + # all source code + _rwx_code="${_rwx_code}\ +#. ${name} +${text} +" +} + +# ╭──────┬────────╮ +# │ main │ source │ +# ╰──────┴────────╯ + +# source code from file path +rwx_source() { + local root="${1}" + [ -d "${root}" ] || + return 1 + local file="${2}" + local count module modules + count=0 + __rwx_log "" \ + ". ${root}" + modules="$(rwx_find_shell "${root}" "${file}")" + while IFS= read -r module; do + count=$((count + 1)) + __rwx_log "$(printf "%02d" "${count}") ${module%.sh}" + # shellcheck disable=SC1090 + . "${root}/${module}" + # cache code + rwx_cache "${root}" "${module}" + done <