simplify
This commit is contained in:
parent
222972b6df
commit
e060c18949
4 changed files with 23 additions and 25 deletions
42
sh/main.sh
42
sh/main.sh
|
@ -8,8 +8,8 @@
|
|||
# │ main │ constants │
|
||||
# ╰──────┴───────────╯
|
||||
|
||||
# name of the entrypoint file
|
||||
RWX_MAIN_NAME="main.sh"
|
||||
# name of the entrypoint module
|
||||
RWX_MAIN_NAME="main"
|
||||
# name of the project itself
|
||||
RWX_SELF_NAME="rwx"
|
||||
|
||||
|
@ -30,21 +30,18 @@ RWX_ROOT_SYSTEM="/usr/local/lib/${RWX_SELF_NAME}"
|
|||
|
||||
# find directory’s shell files
|
||||
#| find
|
||||
#| sed
|
||||
#| sort
|
||||
rwx_main_find() {
|
||||
local root="${1}"
|
||||
local file="${2}"
|
||||
set -- \
|
||||
find \
|
||||
"${root}" \
|
||||
-name "*.sh" \
|
||||
-type "f"
|
||||
[ -n "${file}" ] &&
|
||||
set -- "${@}" \
|
||||
-not \
|
||||
-name "${file}"
|
||||
find "${@}" \
|
||||
-type "f" \
|
||||
-printf "%P\n" |
|
||||
sort
|
||||
sed "s|\\.[^.]*\$||" |
|
||||
sort
|
||||
}
|
||||
|
||||
# ╭──────┬───────╮
|
||||
|
@ -77,24 +74,25 @@ _rwx_main_log() {
|
|||
# │ main │ source │
|
||||
# ╰──────┴────────╯
|
||||
|
||||
# source code from root path but file
|
||||
# source code from root path
|
||||
rwx_main_source() {
|
||||
local root="${1}"
|
||||
[ -d "${root}" ] ||
|
||||
return 1
|
||||
local file="${2}"
|
||||
local count module modules
|
||||
count=0
|
||||
_rwx_main_log "" \
|
||||
". ${root}"
|
||||
modules="$(rwx_main_find "${root}" "${file}")"
|
||||
modules="$(rwx_main_find "${root}")"
|
||||
while IFS= read -r module; do
|
||||
count=$((count + 1))
|
||||
_rwx_main_log "$(printf "%02d" "${count}") ${module%.sh}"
|
||||
# shellcheck disable=SC1090
|
||||
. "${root}/${module}"
|
||||
# cache code
|
||||
rwx_main_cache "${root}" "${module}"
|
||||
if [ "${module}" != "${RWX_MAIN_NAME}" ]; then
|
||||
count=$((count + 1))
|
||||
_rwx_main_log "$(printf "%02d" "${count}") ${module}"
|
||||
# shellcheck disable=SC1090
|
||||
. "${root}/${module}.sh"
|
||||
# cache code
|
||||
rwx_main_cache "${root}" "${module}"
|
||||
fi
|
||||
done <<EOF
|
||||
${modules}
|
||||
EOF
|
||||
|
@ -110,8 +108,8 @@ EOF
|
|||
rwx_main_cache() {
|
||||
local root="${1}"
|
||||
local module="${2}"
|
||||
local name="${module%.sh}"
|
||||
local path="${root}/${module}"
|
||||
local name="${module}"
|
||||
local path="${root}/${module}.sh"
|
||||
local text
|
||||
text="$(cat "${path}")"
|
||||
# all source code
|
||||
|
@ -131,7 +129,7 @@ rwx_main_main() {
|
|||
# cache main
|
||||
rwx_main_cache "${RWX_ROOT_SYSTEM}" "${RWX_MAIN_NAME}"
|
||||
# source system root
|
||||
if ! rwx_main_source "${RWX_ROOT_SYSTEM}" "${RWX_MAIN_NAME}"; then
|
||||
if ! rwx_main_source "${RWX_ROOT_SYSTEM}"; then
|
||||
_rwx_main_log "Not a directory: ${RWX_ROOT_SYSTEM}"
|
||||
return 1
|
||||
fi
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue