Compare commits
10 commits
67e8f3a89c
...
99de96a393
Author | SHA1 | Date | |
---|---|---|---|
99de96a393 | |||
0593181f10 | |||
e060c18949 | |||
222972b6df | |||
048f41cd05 | |||
c11edc243f | |||
e9b57b693c | |||
bf0e3943d8 | |||
71a1ba6516 | |||
5c29d484d4 |
5 changed files with 47 additions and 58 deletions
|
@ -8,12 +8,12 @@
|
||||||
|
|
||||||
# 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}.${RWX_MAIN_EXTENSION}"
|
||||||
# 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}"
|
||||||
|
|
||||||
# cache for the parsing awk script
|
# cache for the parsing awk script
|
||||||
_rwx_code_awk="$(cat "${RWX_ROOT_SYSTEM}/code.awk")"
|
_rwx_code_awk="$(cat "${RWX_ROOT_SYSTEM}/core/code.awk")"
|
||||||
# cache for code aliases
|
# cache for code aliases
|
||||||
_rwx_code_aliases=""
|
_rwx_code_aliases=""
|
||||||
# cache for code aliases functions
|
# cache for code aliases functions
|
||||||
|
@ -37,7 +37,7 @@ _rwx_code_variables=""
|
||||||
|
|
||||||
# output help message
|
# output help message
|
||||||
rwx_code_help() {
|
rwx_code_help() {
|
||||||
rwx_log \
|
rwx_log "" \
|
||||||
"rwx_… = functions" \
|
"rwx_… = functions" \
|
||||||
" a__… = aliases" \
|
" a__… = aliases" \
|
||||||
" u__… = user"
|
" u__… = user"
|
||||||
|
@ -59,7 +59,7 @@ rwx_code_install() {
|
||||||
fi
|
fi
|
||||||
# commands
|
# commands
|
||||||
root="${target}/usr/local/bin"
|
root="${target}/usr/local/bin"
|
||||||
name="${RWX_SELF_NAME}.sh"
|
name="${RWX_SELF_NAME}.${RWX_MAIN_EXTENSION}"
|
||||||
file="${root}/${name}"
|
file="${root}/${name}"
|
||||||
rwx_remove "${file}"
|
rwx_remove "${file}"
|
||||||
rwx_link "${file}" "${RWX_MAIN_PATH}"
|
rwx_link "${file}" "${RWX_MAIN_PATH}"
|
||||||
|
@ -71,7 +71,7 @@ rwx_code_install() {
|
||||||
${_rwx_code_commands}
|
${_rwx_code_commands}
|
||||||
EOF
|
EOF
|
||||||
# sh
|
# sh
|
||||||
file="${target}/etc/profile.d/${RWX_SELF_NAME}.sh"
|
file="${target}/etc/profile.d/${RWX_SELF_NAME}.${RWX_MAIN_EXTENSION}"
|
||||||
rwx_remove "${file}"
|
rwx_remove "${file}"
|
||||||
rwx_file_write "${file}" "\
|
rwx_file_write "${file}" "\
|
||||||
export ENV=\"${RWX_MAIN_PATH}\"
|
export ENV=\"${RWX_MAIN_PATH}\"
|
||||||
|
@ -109,8 +109,8 @@ rwx_code_command_function() {
|
||||||
[ -n "${name}" ] || return
|
[ -n "${name}" ] || return
|
||||||
rwx_code |
|
rwx_code |
|
||||||
awk \
|
awk \
|
||||||
--assign action="command function" \
|
-v action="command function" \
|
||||||
--assign target="${name}" \
|
-v target="${name}" \
|
||||||
"${_rwx_code_awk}"
|
"${_rwx_code_awk}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -175,13 +175,13 @@ rwx_code_doc() {
|
||||||
[ -n "${name}" ] || return
|
[ -n "${name}" ] || return
|
||||||
rwx_code |
|
rwx_code |
|
||||||
awk \
|
awk \
|
||||||
--assign action="doc" \
|
-v action="doc" \
|
||||||
--assign target="${name}" \
|
-v target="${name}" \
|
||||||
"${_rwx_code_awk}"
|
"${_rwx_code_awk}"
|
||||||
}
|
}
|
||||||
|
|
||||||
rwx_code_load() {
|
rwx_code_load() {
|
||||||
local line text
|
local line
|
||||||
# parse aliases functions
|
# parse aliases functions
|
||||||
_rwx_code_aliases_functions="$(rwx_code_parse "aliases functions")"
|
_rwx_code_aliases_functions="$(rwx_code_parse "aliases functions")"
|
||||||
while IFS= read -r line; do
|
while IFS= read -r line; do
|
||||||
|
@ -214,7 +214,7 @@ rwx_code_parse() {
|
||||||
local action="${1}"
|
local action="${1}"
|
||||||
rwx_code |
|
rwx_code |
|
||||||
awk \
|
awk \
|
||||||
--assign action="${action}" \
|
-v action="${action}" \
|
||||||
"${_rwx_code_awk}"
|
"${_rwx_code_awk}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -246,11 +246,7 @@ rwx_code_main() {
|
||||||
fi
|
fi
|
||||||
# context / shell
|
# context / shell
|
||||||
else
|
else
|
||||||
# run interactive extras
|
# display help
|
||||||
if rwx_shell_interactive; then
|
|
||||||
# help
|
|
||||||
rwx_log
|
|
||||||
rwx_code_help
|
rwx_code_help
|
||||||
fi
|
fi
|
||||||
fi
|
|
||||||
}
|
}
|
|
@ -2,9 +2,9 @@ rwx_shellcheck() {
|
||||||
local root="${1}"
|
local root="${1}"
|
||||||
local file module modules path
|
local file module modules path
|
||||||
file="$(mktemp)"
|
file="$(mktemp)"
|
||||||
modules="$(rwx_find_shell "${root}")"
|
modules="$(rwx_main_find "${root}")"
|
||||||
while IFS= read -r module; do
|
while IFS= read -r module; do
|
||||||
path="${root}/${module}"
|
path="${root}/${module}.${RWX_MAIN_EXTENSION}"
|
||||||
echo ". \"${path}\"" >>"${file}"
|
echo ". \"${path}\"" >>"${file}"
|
||||||
done <<EOF
|
done <<EOF
|
||||||
${modules}
|
${modules}
|
||||||
|
|
57
sh/main.sh
57
sh/main.sh
|
@ -8,8 +8,11 @@
|
||||||
# │ main │ constants │
|
# │ main │ constants │
|
||||||
# ╰──────┴───────────╯
|
# ╰──────┴───────────╯
|
||||||
|
|
||||||
# name of the entrypoint file
|
# extension of shell modules
|
||||||
RWX_MAIN_NAME="main.sh"
|
RWX_MAIN_EXTENSION="sh"
|
||||||
|
|
||||||
|
# name of the entrypoint module
|
||||||
|
RWX_MAIN_NAME="main"
|
||||||
# name of the project itself
|
# name of the project itself
|
||||||
RWX_SELF_NAME="rwx"
|
RWX_SELF_NAME="rwx"
|
||||||
|
|
||||||
|
@ -28,37 +31,27 @@ RWX_ROOT_SYSTEM="/usr/local/lib/${RWX_SELF_NAME}"
|
||||||
# │ main │ find │
|
# │ main │ find │
|
||||||
# ╰──────┴──────╯
|
# ╰──────┴──────╯
|
||||||
|
|
||||||
# find directory’s files by extension
|
# find directory’s shell files
|
||||||
#| find
|
#| find
|
||||||
|
#| sed
|
||||||
#| sort
|
#| sort
|
||||||
rwx_find_extension() {
|
rwx_main_find() {
|
||||||
local extension="${1}"
|
local root="${1}"
|
||||||
local root="${2}"
|
find \
|
||||||
local file="${3}"
|
|
||||||
set -- \
|
|
||||||
"${root}" \
|
"${root}" \
|
||||||
-name "*.${extension}" \
|
-name "*.${RWX_MAIN_EXTENSION}" \
|
||||||
-type "f"
|
-type "f" \
|
||||||
[ -n "${file}" ] &&
|
|
||||||
set -- "${@}" \
|
|
||||||
-not \
|
|
||||||
-name "${file}"
|
|
||||||
find "${@}" \
|
|
||||||
-printf "%P\n" |
|
-printf "%P\n" |
|
||||||
|
sed "s|\\.[^.]*\$||" |
|
||||||
sort
|
sort
|
||||||
}
|
}
|
||||||
|
|
||||||
# find directory’s sh files
|
|
||||||
rwx_find_shell() {
|
|
||||||
rwx_find_extension "sh" "${@}"
|
|
||||||
}
|
|
||||||
|
|
||||||
# ╭──────┬───────╮
|
# ╭──────┬───────╮
|
||||||
# │ main │ shell │
|
# │ main │ shell │
|
||||||
# ╰──────┴───────╯
|
# ╰──────┴───────╯
|
||||||
|
|
||||||
# test if active shell is in interactive mode
|
# test if active shell is in interactive mode
|
||||||
rwx_shell_interactive() {
|
rwx_main_interactive() {
|
||||||
case "${-}" in
|
case "${-}" in
|
||||||
*i*) ;;
|
*i*) ;;
|
||||||
*) return 1 ;;
|
*) return 1 ;;
|
||||||
|
@ -70,7 +63,7 @@ rwx_shell_interactive() {
|
||||||
# ╰──────┴─────╯
|
# ╰──────┴─────╯
|
||||||
|
|
||||||
_rwx_main_log() {
|
_rwx_main_log() {
|
||||||
if rwx_shell_interactive; then
|
if rwx_main_interactive; then
|
||||||
[ ${#} -gt 0 ] || set -- ""
|
[ ${#} -gt 0 ] || set -- ""
|
||||||
local line
|
local line
|
||||||
for line in "${@}"; do
|
for line in "${@}"; do
|
||||||
|
@ -83,24 +76,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_find_shell "${root}" "${file}")"
|
modules="$(rwx_main_find "${root}")"
|
||||||
while IFS= read -r module; do
|
while IFS= read -r module; do
|
||||||
|
if [ "${module}" != "${RWX_MAIN_NAME}" ]; then
|
||||||
count=$((count + 1))
|
count=$((count + 1))
|
||||||
_rwx_main_log "$(printf "%02d" "${count}") ${module%.sh}"
|
_rwx_main_log "$(printf "%02d" "${count}") ${module}"
|
||||||
# shellcheck disable=SC1090
|
# shellcheck disable=SC1090
|
||||||
. "${root}/${module}"
|
. "${root}/${module}.${RWX_MAIN_EXTENSION}"
|
||||||
# cache code
|
# cache code
|
||||||
rwx_main_cache "${root}" "${module}"
|
rwx_main_cache "${root}" "${module}"
|
||||||
|
fi
|
||||||
done <<EOF
|
done <<EOF
|
||||||
${modules}
|
${modules}
|
||||||
EOF
|
EOF
|
||||||
|
@ -116,13 +110,12 @@ EOF
|
||||||
rwx_main_cache() {
|
rwx_main_cache() {
|
||||||
local root="${1}"
|
local root="${1}"
|
||||||
local module="${2}"
|
local module="${2}"
|
||||||
local name="${module%.sh}"
|
local path="${root}/${module}.${RWX_MAIN_EXTENSION}"
|
||||||
local path="${root}/${module}"
|
|
||||||
local text
|
local text
|
||||||
text="$(cat "${path}")"
|
text="$(cat "${path}")"
|
||||||
# all source code
|
# all source code
|
||||||
_rwx_code="${_rwx_code}\
|
_rwx_code="${_rwx_code}\
|
||||||
#. ${name}
|
#. ${module}
|
||||||
${text}
|
${text}
|
||||||
"
|
"
|
||||||
}
|
}
|
||||||
|
@ -132,12 +125,12 @@ ${text}
|
||||||
# ╰──────┴──────╯
|
# ╰──────┴──────╯
|
||||||
|
|
||||||
# run initial steps
|
# run initial steps
|
||||||
#< code
|
#< core/code
|
||||||
rwx_main_main() {
|
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
|
||||||
|
|
|
@ -11,11 +11,11 @@ rwx_self_subset() {
|
||||||
local argument file root
|
local argument file root
|
||||||
for argument in "${@}"; do
|
for argument in "${@}"; do
|
||||||
root="${RWX_ROOT_SYSTEM}/${argument}"
|
root="${RWX_ROOT_SYSTEM}/${argument}"
|
||||||
file="${argument}.sh"
|
file="${argument}.${RWX_MAIN_EXTENSION}"
|
||||||
if [ -d "${root}" ]; then
|
if [ -d "${root}" ]; then
|
||||||
local file
|
local file
|
||||||
for file in $(rwx_find_shell "${root}"); do
|
for file in $(rwx_main_find "${root}"); do
|
||||||
echo "${argument}/${file}"
|
echo "${argument}/${file}.${RWX_MAIN_EXTENSION}"
|
||||||
done
|
done
|
||||||
elif [ -f "${RWX_ROOT_SYSTEM}/${file}" ]; then
|
elif [ -f "${RWX_ROOT_SYSTEM}/${file}" ]; then
|
||||||
echo "${file}"
|
echo "${file}"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue