This commit is contained in:
Marc Beninca 2025-07-04 03:35:51 +02:00
parent 3da235e09e
commit 47882c10fe
Signed by: marc.beninca
GPG key ID: 9C7613450C80C24F
2 changed files with 47 additions and 33 deletions

View file

@ -8,6 +8,7 @@
# │ main │ constants │
# ╰──────┴───────────╯
# name of the entrypoint file
RWX_MAIN_NAME="main.sh"
RWX_SELF_NAME="rwx"
@ -61,37 +62,22 @@ 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}")"
[ -n "${RWX_CODE}" ] && RWX_CODE="${RWX_CODE}
"
RWX_CODE="${RWX_CODE}\
# ╭───┬────┬─${fill}─╮
# │ ↙ │ sh │ ${name} │
# ╰───┴────┴─${fill}─╯
#↓ ${name}
${text}
"
}
# ╭──────┬──────╮
# │ main │ fill │
# ╰──────┴──────╯
rwx_fill() {
local index="${1}"
while [ "${index}" -gt 0 ]; do
printf "%s" "${2}"
index=$((index - 1))
done
}
# ╭──────┬────────╮
# │ main │ source │
# ╰──────┴────────╯

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
case "${line}" in
"#"*) doc="${doc}${line}" ;;
"${name}() {")
echo "${doc}"
return
local constant doc func line module
printf "%s\n" "${RWX_CODE}" | while IFS= read -r line; do
case "${line}" in
"#!"*) doc="" ;;
"#↓"*)
doc=""
module="$(echo "${line}" | sed "s|#↓ \\(.*\\)|\\1|")"
;;
*) doc="" ;;
esac
done <"${RWX_ROOT_SYSTEM}/${module}"
"#"*)
[ -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
;;
esac
done
rwx_ifs_unset
}
# ╭──────┬───────╮