code/load

This commit is contained in:
Marc Beninca 2025-07-07 02:58:39 +02:00
parent 45f0ebbb9b
commit 0b12a7545e
Signed by: marc.beninca
GPG key ID: 9C7613450C80C24F
2 changed files with 53 additions and 57 deletions

View file

@ -89,3 +89,54 @@ rwx_code_doc() {
--assign target="${name}" \
"${_rwx_code_awk}"
}
rwx_code_load() {
# parse aliases
_rwx_code_aliases="$(rwx_parse_aliases)"
# parse aliases functions
local line text
_rwx_code_aliases_functions="$(rwx_parse_aliases_functions)"
while IFS= read -r line; do
text="$(echo "${line}" | sed "s| |() { |")"
text="${text} \"\${@}\"; }"
eval "${text}"
done <<EOF
${_rwx_code_aliases_functions}
EOF
# parse constants
_rwx_code_constants="$(rwx_parse_constants)"
# parse functions
_rwx_code_functions="$(rwx_parse_functions)"
# parse variables
_rwx_code_variables="$(rwx_parse_variables)"
}
rwx_parse_aliases() {
rwx_code |
awk \
--assign action="aliases" \
"${_rwx_code_awk}"
}
rwx_parse_aliases_functions() {
rwx_code |
awk \
--assign action="aliases functions" \
"${_rwx_code_awk}"
}
rwx_parse_constants() {
rwx_code |
awk \
--assign action="constants" \
"${_rwx_code_awk}"
}
rwx_parse_functions() {
rwx_code |
awk \
--assign action="functions" \
"${_rwx_code_awk}"
}
rwx_parse_variables() {
rwx_code |
awk \
--assign action="variables" \
"${_rwx_code_awk}"
}

View file

@ -63,8 +63,8 @@ rwx_main() {
fi
# source user root
rwx_source "${RWX_SELF_USER}"
# parse code cache
rwx_parse_code
# load code cache
rwx_code_load
# context / command
if [ -n "${RWX_COMMAND_NAME}" ]; then
"${RWX_SELF_COMMAND}${RWX_COMMAND_NAME}" "${@}"
@ -177,61 +177,6 @@ rwx_find_shell() {
rwx_find_extension "sh" "${@}"
}
# ╭──────┬───────╮
# │ main │ parse │
# ╰──────┴───────╯
rwx_parse_code() {
# parse aliases
_rwx_code_aliases="$(rwx_parse_aliases)"
# parse aliases functions
local line text
_rwx_code_aliases_functions="$(rwx_parse_aliases_functions)"
while IFS= read -r line; do
text="$(echo "${line}" | sed "s| |() { |")"
text="${text} \"\${@}\"; }"
eval "${text}"
done <<EOF
${_rwx_code_aliases_functions}
EOF
# parse constants
_rwx_code_constants="$(rwx_parse_constants)"
# parse functions
_rwx_code_functions="$(rwx_parse_functions)"
# parse variables
_rwx_code_variables="$(rwx_parse_variables)"
}
rwx_parse_aliases() {
rwx_code |
awk \
--assign action="aliases" \
"${_rwx_code_awk}"
}
rwx_parse_aliases_functions() {
rwx_code |
awk \
--assign action="aliases functions" \
"${_rwx_code_awk}"
}
rwx_parse_constants() {
rwx_code |
awk \
--assign action="constants" \
"${_rwx_code_awk}"
}
rwx_parse_functions() {
rwx_code |
awk \
--assign action="functions" \
"${_rwx_code_awk}"
}
rwx_parse_variables() {
rwx_code |
awk \
--assign action="variables" \
"${_rwx_code_awk}"
}
# ╭──────┬─────╮
# │ main │ run │
# ╰──────┴─────╯