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
|
#! /usr/bin/env sh
|
||||||
|
# main module
|
||||||
|
|
||||||
# ╭──────╮
|
# ╭──────╮
|
||||||
# │ main │
|
# │ main │
|
||||||
|
@ -8,6 +9,7 @@
|
||||||
# │ main │ constants │
|
# │ main │ constants │
|
||||||
# ╰──────┴───────────╯
|
# ╰──────┴───────────╯
|
||||||
|
|
||||||
|
# name of the entrypoint file
|
||||||
RWX_MAIN_NAME="main.sh"
|
RWX_MAIN_NAME="main.sh"
|
||||||
RWX_SELF_NAME="rwx"
|
RWX_SELF_NAME="rwx"
|
||||||
|
|
||||||
|
@ -61,44 +63,20 @@ rwx_main() {
|
||||||
# │ main │ cache │
|
# │ main │ cache │
|
||||||
# ╰──────┴───────╯
|
# ╰──────┴───────╯
|
||||||
|
|
||||||
|
RWX_CODE=""
|
||||||
|
|
||||||
|
# cache source code of a module
|
||||||
rwx_cache() {
|
rwx_cache() {
|
||||||
local root="${1}"
|
local root="${1}"
|
||||||
local module="${2}"
|
local module="${2}"
|
||||||
local name="${module%.sh}"
|
local name="${module%.sh}"
|
||||||
local path="${root}/${module}"
|
local path="${root}/${module}"
|
||||||
local fill text
|
local text
|
||||||
fill="$(rwx_fill "${#name}" ─)"
|
|
||||||
text="$(cat "${path}")"
|
text="$(cat "${path}")"
|
||||||
case "${text}" in
|
RWX_CODE="${RWX_CODE}\
|
||||||
"#!"*)
|
#↓ ${name}
|
||||||
RWX_CODE="${text}
|
${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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# ╭──────┬────────╮
|
# ╭──────┬────────╮
|
||||||
|
@ -115,16 +93,17 @@ rwx_source() {
|
||||||
count=0
|
count=0
|
||||||
__rwx_log "" \
|
__rwx_log "" \
|
||||||
". ${root}"
|
". ${root}"
|
||||||
rwx_ifs_set
|
local modules="$(rwx_find_shell "${root}" "${file}")"
|
||||||
for module in $(rwx_find_shell "${root}" "${file}"); do
|
while IFS= read -r module; do
|
||||||
count=$((count + 1))
|
count=$((count + 1))
|
||||||
__rwx_log "$(printf "%02d" "${count}") ${module%.sh}"
|
__rwx_log "$(printf "%02d" "${count}") ${module%.sh}"
|
||||||
# shellcheck disable=SC1090
|
# shellcheck disable=SC1090
|
||||||
. "${root}/${module}"
|
. "${root}/${module}"
|
||||||
# cache code
|
# cache code
|
||||||
rwx_cache "${root}" "${module}"
|
rwx_cache "${root}" "${module}"
|
||||||
done
|
done <<EOF
|
||||||
rwx_ifs_unset
|
${modules}
|
||||||
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
# ╭──────┬─────╮
|
# ╭──────┬─────╮
|
||||||
|
@ -209,22 +188,22 @@ rwx_parse() {
|
||||||
local func="${ws}(${ws})${ws}{.*"
|
local func="${ws}(${ws})${ws}{.*"
|
||||||
local id="[_a-zA-Z][_a-z0-9A-Z]*"
|
local id="[_a-zA-Z][_a-z0-9A-Z]*"
|
||||||
local line
|
local line
|
||||||
rwx_ifs_set
|
|
||||||
RWX_CONSTANTS=""
|
RWX_CONSTANTS=""
|
||||||
for line in $(echo "${RWX_CODE}" |
|
printf "%s\n" "${RWX_CODE}" |
|
||||||
grep "${start}${constant}${setting}" |
|
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}
|
RWX_CONSTANTS="${RWX_CONSTANTS}${line}
|
||||||
"
|
"
|
||||||
done
|
done
|
||||||
RWX_FUNCTIONS=""
|
RWX_FUNCTIONS=""
|
||||||
for line in $(echo "${RWX_CODE}" |
|
printf "%s\n" "${RWX_CODE}" |
|
||||||
grep "${start}${id}${func}" |
|
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}
|
RWX_FUNCTIONS="${RWX_FUNCTIONS}${line}
|
||||||
"
|
"
|
||||||
done
|
done
|
||||||
rwx_ifs_unset
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# ╭──────┬─────╮
|
# ╭──────┬─────╮
|
||||||
|
|
59
sh/self.sh
59
sh/self.sh
|
@ -1,22 +1,50 @@
|
||||||
|
# self module
|
||||||
|
|
||||||
# meta doc
|
# meta doc
|
||||||
rwx_doc() {
|
rwx_doc() {
|
||||||
local name="${1}"
|
local name="${1}"
|
||||||
[ -n "${name}" ] || return
|
[ -n "${name}" ] || return
|
||||||
local doc line module
|
local constant doc func line module
|
||||||
rwx_ifs_set
|
printf "%s\n" "${RWX_CODE}" | while IFS= read -r line; do
|
||||||
for module in $(rwx_find_shell "${RWX_ROOT_SYSTEM}"); do
|
|
||||||
while read -r line; do
|
|
||||||
case "${line}" in
|
case "${line}" in
|
||||||
"#"*) doc="${doc}${line}" ;;
|
"#!"*) doc="" ;;
|
||||||
"${name}() {")
|
"#↓"*)
|
||||||
|
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}"
|
echo "${doc}"
|
||||||
return
|
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
|
esac
|
||||||
done <"${RWX_ROOT_SYSTEM}/${module}"
|
|
||||||
done
|
done
|
||||||
rwx_ifs_unset
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# ╭──────┬───────╮
|
# ╭──────┬───────╮
|
||||||
|
@ -127,16 +155,17 @@ export ENV=\"${RWX_MAIN_PATH}\"
|
||||||
# ╰──────┴────────╯
|
# ╰──────┴────────╯
|
||||||
|
|
||||||
rwx_self_subset() {
|
rwx_self_subset() {
|
||||||
local argument path
|
local argument file root
|
||||||
for argument in "${@}"; do
|
for argument in "${@}"; do
|
||||||
path="${RWX_ROOT_SYSTEM}/${argument}"
|
root="${RWX_ROOT_SYSTEM}/${argument}"
|
||||||
if [ -d "${path}" ]; then
|
file="${argument}.sh"
|
||||||
|
if [ -d "${root}" ]; then
|
||||||
local file
|
local file
|
||||||
for file in $(rwx_find_shell "${path}"); do
|
for file in $(rwx_find_shell "${root}"); do
|
||||||
echo "${argument}/${file}"
|
echo "${argument}/${file}"
|
||||||
done
|
done
|
||||||
elif [ -f "${path}" ]; then
|
elif [ -f "${RWX_ROOT_SYSTEM}/${file}" ]; then
|
||||||
echo "${argument}"
|
echo "${file}"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue