Compare commits
6 commits
9d7c77b881
...
465f0ba475
Author | SHA1 | Date | |
---|---|---|---|
465f0ba475 | |||
5346091e7b | |||
80632463f6 | |||
651fafe418 | |||
47882c10fe | |||
3da235e09e |
2 changed files with 69 additions and 61 deletions
63
sh/main.sh
63
sh/main.sh
|
@ -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
|
||||
}
|
||||
|
||||
# ╭──────┬─────╮
|
||||
|
|
67
sh/self.sh
67
sh/self.sh
|
@ -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
|
||||
}
|
||||
|
||||
# ╭──────┬───────╮
|
||||
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue