This commit is contained in:
Marc Beninca 2025-07-09 02:04:14 +02:00
parent 222972b6df
commit e060c18949
Signed by: marc.beninca
GPG key ID: 9C7613450C80C24F
4 changed files with 23 additions and 25 deletions

View file

@ -8,7 +8,7 @@
# TODO variablize # TODO variablize
# path to the entrypoint main file of the project # path to the entrypoint main file of the project
RWX_MAIN_PATH="${RWX_ROOT_SYSTEM}/${RWX_MAIN_NAME}" RWX_MAIN_PATH="${RWX_ROOT_SYSTEM}/${RWX_MAIN_NAME}.sh"
# user root directory of the project # user root directory of the project
RWX_SELF_USER="${HOME}/${RWX_SELF_NAME}" RWX_SELF_USER="${HOME}/${RWX_SELF_NAME}"

View file

@ -4,7 +4,7 @@ rwx_shellcheck() {
file="$(mktemp)" file="$(mktemp)"
modules="$(rwx_main_find "${root}")" modules="$(rwx_main_find "${root}")"
while IFS= read -r module; do while IFS= read -r module; do
path="${root}/${module}" path="${root}/${module}.sh"
echo ". \"${path}\"" >>"${file}" echo ". \"${path}\"" >>"${file}"
done <<EOF done <<EOF
${modules} ${modules}

View file

@ -8,8 +8,8 @@
# │ main │ constants │ # │ main │ constants │
# ╰──────┴───────────╯ # ╰──────┴───────────╯
# name of the entrypoint file # name of the entrypoint module
RWX_MAIN_NAME="main.sh" RWX_MAIN_NAME="main"
# name of the project itself # name of the project itself
RWX_SELF_NAME="rwx" RWX_SELF_NAME="rwx"
@ -30,21 +30,18 @@ RWX_ROOT_SYSTEM="/usr/local/lib/${RWX_SELF_NAME}"
# find directory’s shell files # find directory’s shell files
#| find #| find
#| sed
#| sort #| sort
rwx_main_find() { rwx_main_find() {
local root="${1}" local root="${1}"
local file="${2}" local file="${2}"
set -- \ find \
"${root}" \ "${root}" \
-name "*.sh" \ -name "*.sh" \
-type "f" -type "f" \
[ -n "${file}" ] &&
set -- "${@}" \
-not \
-name "${file}"
find "${@}" \
-printf "%P\n" | -printf "%P\n" |
sort sed "s|\\.[^.]*\$||" |
sort
} }
# ╭──────┬───────╮ # ╭──────┬───────╮
@ -77,24 +74,25 @@ _rwx_main_log() {
# │ main │ source │ # │ main │ source │
# ╰──────┴────────╯ # ╰──────┴────────╯
# source code from root path but file # source code from root path
rwx_main_source() { rwx_main_source() {
local root="${1}" local root="${1}"
[ -d "${root}" ] || [ -d "${root}" ] ||
return 1 return 1
local file="${2}"
local count module modules local count module modules
count=0 count=0
_rwx_main_log "" \ _rwx_main_log "" \
". ${root}" ". ${root}"
modules="$(rwx_main_find "${root}" "${file}")" modules="$(rwx_main_find "${root}")"
while IFS= read -r module; do while IFS= read -r module; do
count=$((count + 1)) if [ "${module}" != "${RWX_MAIN_NAME}" ]; then
_rwx_main_log "$(printf "%02d" "${count}") ${module%.sh}" count=$((count + 1))
# shellcheck disable=SC1090 _rwx_main_log "$(printf "%02d" "${count}") ${module}"
. "${root}/${module}" # shellcheck disable=SC1090
# cache code . "${root}/${module}.sh"
rwx_main_cache "${root}" "${module}" # cache code
rwx_main_cache "${root}" "${module}"
fi
done <<EOF done <<EOF
${modules} ${modules}
EOF EOF
@ -110,8 +108,8 @@ EOF
rwx_main_cache() { rwx_main_cache() {
local root="${1}" local root="${1}"
local module="${2}" local module="${2}"
local name="${module%.sh}" local name="${module}"
local path="${root}/${module}" local path="${root}/${module}.sh"
local text local text
text="$(cat "${path}")" text="$(cat "${path}")"
# all source code # all source code
@ -131,7 +129,7 @@ rwx_main_main() {
# cache main # cache main
rwx_main_cache "${RWX_ROOT_SYSTEM}" "${RWX_MAIN_NAME}" rwx_main_cache "${RWX_ROOT_SYSTEM}" "${RWX_MAIN_NAME}"
# source system root # 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}" _rwx_main_log "Not a directory: ${RWX_ROOT_SYSTEM}"
return 1 return 1
fi fi

View file

@ -15,7 +15,7 @@ rwx_self_subset() {
if [ -d "${root}" ]; then if [ -d "${root}" ]; then
local file local file
for file in $(rwx_main_find "${root}"); do for file in $(rwx_main_find "${root}"); do
echo "${argument}/${file}" echo "${argument}/${file}.sh"
done done
elif [ -f "${RWX_ROOT_SYSTEM}/${file}" ]; then elif [ -f "${RWX_ROOT_SYSTEM}/${file}" ]; then
echo "${file}" echo "${file}"