Compare commits

..

6 commits

Author SHA1 Message Date
465f0ba475
subset/file,root
All checks were successful
/ job (push) Successful in 4m27s
2025-07-04 04:53:46 +02:00
5346091e7b
−ifs 2025-07-04 04:34:26 +02:00
80632463f6
−ifs 2025-07-04 03:52:38 +02:00
651fafe418
main/doc 2025-07-04 03:39:58 +02:00
47882c10fe
doc/wip 2025-07-04 03:35:51 +02:00
3da235e09e
cache/same 2025-07-04 01:17:12 +02:00
2 changed files with 69 additions and 61 deletions

View file

@ -1,4 +1,5 @@
#! /usr/bin/env sh
# main module
# ╭──────╮
# │ main │
@ -8,6 +9,7 @@
# │ main │ constants │
# ╰──────┴───────────╯
# name of the entrypoint file
RWX_MAIN_NAME="main.sh"
RWX_SELF_NAME="rwx"
@ -61,44 +63,20 @@ rwx_main() {
# │ main │ cache │
# ╰──────┴───────╯
RWX_CODE=""
# cache source code of a module
rwx_cache() {
local root="${1}"
local module="${2}"
local name="${module%.sh}"
local path="${root}/${module}"
local fill text
fill="$(rwx_fill "${#name}")"
local text
text="$(cat "${path}")"
case "${text}" in
"#!"*)
RWX_CODE="${text}
# ╭───┬────┬─${fill}─╮
# │ ↖ │ sh │ ${name} │
# ╰───┴────┴─${fill}─╯"
;;
*)
RWX_CODE="${RWX_CODE}
# ╭───┬────┬─${fill}─╮
# │ ↙ │ sh │ ${name} │
# ╰───┴────┴─${fill}─╯
${text}"
;;
esac
}
# ╭──────┬──────╮
# │ main │ fill │
# ╰──────┴──────╯
rwx_fill() {
local index="${1}"
while [ "${index}" -gt 0 ]; do
printf "%s" "${2}"
index=$((index - 1))
done
RWX_CODE="${RWX_CODE}\
#↓ ${name}
${text}
"
}
# ╭──────┬────────╮
@ -115,16 +93,17 @@ rwx_source() {
count=0
__rwx_log "" \
". ${root}"
rwx_ifs_set
for module in $(rwx_find_shell "${root}" "${file}"); do
local 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
rwx_ifs_unset
done <<EOF
${modules}
EOF
}
# ╭──────┬─────╮
@ -209,22 +188,22 @@ rwx_parse() {
local func="${ws}(${ws})${ws}{.*"
local id="[_a-zA-Z][_a-z0-9A-Z]*"
local line
rwx_ifs_set
RWX_CONSTANTS=""
for line in $(echo "${RWX_CODE}" |
printf "%s\n" "${RWX_CODE}" |
grep "${start}${constant}${setting}" |
sed "s|${start}\\(${constant}\\)${setting}|\\1|"); do
sed "s|${start}\\(${constant}\\)${setting}|\\1|" |
while IFS= read -r line; do
RWX_CONSTANTS="${RWX_CONSTANTS}${line}
"
done
RWX_FUNCTIONS=""
for line in $(echo "${RWX_CODE}" |
printf "%s\n" "${RWX_CODE}" |
grep "${start}${id}${func}" |
sed "s|${start}\\(${id}\\)${func}|\\1|"); do
sed "s|${start}\\(${id}\\)${func}|\\1|" |
while IFS= read -r line; do
RWX_FUNCTIONS="${RWX_FUNCTIONS}${line}
"
done
rwx_ifs_unset
}
# ╭──────┬─────╮

View file

@ -1,22 +1,50 @@
# self module
# meta doc
rwx_doc() {
local name="${1}"
[ -n "${name}" ] || return
local doc line module
rwx_ifs_set
for module in $(rwx_find_shell "${RWX_ROOT_SYSTEM}"); do
while read -r line; do
local constant doc func line module
printf "%s\n" "${RWX_CODE}" | while IFS= read -r line; do
case "${line}" in
"#"*) doc="${doc}${line}" ;;
"${name}() {")
"#!"*) doc="" ;;
"#↓"*)
doc=""
module="$(echo "${line}" | sed "s|#↓ \\(.*\\)|\\1|")"
;;
"#"*)
[ -n "${doc}" ] && doc="${doc}
"
doc="${doc}${line}"
;;
*"="*)
constant="$(echo "${line}" | sed "s|^\\(.*\\)=.*|\\1|")"
if [ "${constant}" = "${name}" ]; then
echo "${doc}"
return
else
doc=""
fi
;;
*"("*")"*"{"*)
func="$(echo "${line}" | sed "s|^\\(.*\\)() {.*|\\1|")"
if [ "${func}" = "${name}" ]; then
echo "${doc}"
return
else
doc=""
fi
;;
*)
if [ "${module}" = "${name}" ]; then
echo "${doc}"
return
else
doc=""
fi
;;
*) doc="" ;;
esac
done <"${RWX_ROOT_SYSTEM}/${module}"
done
rwx_ifs_unset
}
# ╭──────┬───────╮
@ -127,16 +155,17 @@ export ENV=\"${RWX_MAIN_PATH}\"
# ╰──────┴────────╯
rwx_self_subset() {
local argument path
local argument file root
for argument in "${@}"; do
path="${RWX_ROOT_SYSTEM}/${argument}"
if [ -d "${path}" ]; then
root="${RWX_ROOT_SYSTEM}/${argument}"
file="${argument}.sh"
if [ -d "${root}" ]; then
local file
for file in $(rwx_find_shell "${path}"); do
for file in $(rwx_find_shell "${root}"); do
echo "${argument}/${file}"
done
elif [ -f "${path}" ]; then
echo "${argument}"
elif [ -f "${RWX_ROOT_SYSTEM}/${file}" ]; then
echo "${file}"
fi
done
}