Compare commits

..

No commits in common. "99de96a3934912b980a479e2feab2f062a8e52fb" and "67e8f3a89c9e2b75eda3f9c104fe264020dcc8df" have entirely different histories.

5 changed files with 58 additions and 47 deletions

View file

@ -8,12 +8,12 @@
# TODO variablize
# path to the entrypoint main file of the project
RWX_MAIN_PATH="${RWX_ROOT_SYSTEM}/${RWX_MAIN_NAME}.${RWX_MAIN_EXTENSION}"
RWX_MAIN_PATH="${RWX_ROOT_SYSTEM}/${RWX_MAIN_NAME}"
# user root directory of the project
RWX_SELF_USER="${HOME}/${RWX_SELF_NAME}"
# cache for the parsing awk script
_rwx_code_awk="$(cat "${RWX_ROOT_SYSTEM}/core/code.awk")"
_rwx_code_awk="$(cat "${RWX_ROOT_SYSTEM}/code.awk")"
# cache for code aliases
_rwx_code_aliases=""
# cache for code aliases functions
@ -37,7 +37,7 @@ _rwx_code_variables=""
# output help message
rwx_code_help() {
rwx_log "" \
rwx_log \
"rwx_… = functions" \
" a__… = aliases" \
" u__… = user"
@ -59,7 +59,7 @@ rwx_code_install() {
fi
# commands
root="${target}/usr/local/bin"
name="${RWX_SELF_NAME}.${RWX_MAIN_EXTENSION}"
name="${RWX_SELF_NAME}.sh"
file="${root}/${name}"
rwx_remove "${file}"
rwx_link "${file}" "${RWX_MAIN_PATH}"
@ -71,7 +71,7 @@ rwx_code_install() {
${_rwx_code_commands}
EOF
# sh
file="${target}/etc/profile.d/${RWX_SELF_NAME}.${RWX_MAIN_EXTENSION}"
file="${target}/etc/profile.d/${RWX_SELF_NAME}.sh"
rwx_remove "${file}"
rwx_file_write "${file}" "\
export ENV=\"${RWX_MAIN_PATH}\"
@ -109,8 +109,8 @@ rwx_code_command_function() {
[ -n "${name}" ] || return
rwx_code |
awk \
-v action="command function" \
-v target="${name}" \
--assign action="command function" \
--assign target="${name}" \
"${_rwx_code_awk}"
}
@ -175,13 +175,13 @@ rwx_code_doc() {
[ -n "${name}" ] || return
rwx_code |
awk \
-v action="doc" \
-v target="${name}" \
--assign action="doc" \
--assign target="${name}" \
"${_rwx_code_awk}"
}
rwx_code_load() {
local line
local line text
# parse aliases functions
_rwx_code_aliases_functions="$(rwx_code_parse "aliases functions")"
while IFS= read -r line; do
@ -214,7 +214,7 @@ rwx_code_parse() {
local action="${1}"
rwx_code |
awk \
-v action="${action}" \
--assign action="${action}" \
"${_rwx_code_awk}"
}
@ -246,7 +246,11 @@ rwx_code_main() {
fi
# context / shell
else
# display help
rwx_code_help
# run interactive extras
if rwx_shell_interactive; then
# help
rwx_log
rwx_code_help
fi
fi
}

View file

@ -2,9 +2,9 @@ rwx_shellcheck() {
local root="${1}"
local file module modules path
file="$(mktemp)"
modules="$(rwx_main_find "${root}")"
modules="$(rwx_find_shell "${root}")"
while IFS= read -r module; do
path="${root}/${module}.${RWX_MAIN_EXTENSION}"
path="${root}/${module}"
echo ". \"${path}\"" >>"${file}"
done <<EOF
${modules}

View file

@ -8,11 +8,8 @@
# │ main │ constants │
# ╰──────┴───────────╯
# extension of shell modules
RWX_MAIN_EXTENSION="sh"
# name of the entrypoint module
RWX_MAIN_NAME="main"
# name of the entrypoint file
RWX_MAIN_NAME="main.sh"
# name of the project itself
RWX_SELF_NAME="rwx"
@ -31,27 +28,37 @@ RWX_ROOT_SYSTEM="/usr/local/lib/${RWX_SELF_NAME}"
# │ main │ find │
# ╰──────┴──────╯
# find directory’s shell files
# find directory’s files by extension
#| find
#| sed
#| sort
rwx_main_find() {
local root="${1}"
find \
rwx_find_extension() {
local extension="${1}"
local root="${2}"
local file="${3}"
set -- \
"${root}" \
-name "*.${RWX_MAIN_EXTENSION}" \
-type "f" \
-name "*.${extension}" \
-type "f"
[ -n "${file}" ] &&
set -- "${@}" \
-not \
-name "${file}"
find "${@}" \
-printf "%P\n" |
sed "s|\\.[^.]*\$||" |
sort
}
# find directory’s sh files
rwx_find_shell() {
rwx_find_extension "sh" "${@}"
}
# ╭──────┬───────╮
# │ main │ shell │
# ╰──────┴───────╯
# test if active shell is in interactive mode
rwx_main_interactive() {
rwx_shell_interactive() {
case "${-}" in
*i*) ;;
*) return 1 ;;
@ -63,7 +70,7 @@ rwx_main_interactive() {
# ╰──────┴─────╯
_rwx_main_log() {
if rwx_main_interactive; then
if rwx_shell_interactive; then
[ ${#} -gt 0 ] || set -- ""
local line
for line in "${@}"; do
@ -76,25 +83,24 @@ _rwx_main_log() {
# │ main │ source │
# ╰──────┴────────╯
# source code from root path
# source code from root path but file
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}")"
modules="$(rwx_find_shell "${root}" "${file}")"
while IFS= read -r module; do
if [ "${module}" != "${RWX_MAIN_NAME}" ]; then
count=$((count + 1))
_rwx_main_log "$(printf "%02d" "${count}") ${module}"
# shellcheck disable=SC1090
. "${root}/${module}.${RWX_MAIN_EXTENSION}"
# cache code
rwx_main_cache "${root}" "${module}"
fi
count=$((count + 1))
_rwx_main_log "$(printf "%02d" "${count}") ${module%.sh}"
# shellcheck disable=SC1090
. "${root}/${module}"
# cache code
rwx_main_cache "${root}" "${module}"
done <<EOF
${modules}
EOF
@ -110,12 +116,13 @@ EOF
rwx_main_cache() {
local root="${1}"
local module="${2}"
local path="${root}/${module}.${RWX_MAIN_EXTENSION}"
local name="${module%.sh}"
local path="${root}/${module}"
local text
text="$(cat "${path}")"
# all source code
_rwx_code="${_rwx_code}\
#. ${module}
#. ${name}
${text}
"
}
@ -125,12 +132,12 @@ ${text}
# ╰──────┴──────╯
# run initial steps
#< core/code
#< code
rwx_main_main() {
# cache main
rwx_main_cache "${RWX_ROOT_SYSTEM}" "${RWX_MAIN_NAME}"
# source system root
if ! rwx_main_source "${RWX_ROOT_SYSTEM}"; then
if ! rwx_main_source "${RWX_ROOT_SYSTEM}" "${RWX_MAIN_NAME}"; then
_rwx_main_log "Not a directory: ${RWX_ROOT_SYSTEM}"
return 1
fi

View file

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