This commit is contained in:
Marc Beninca 2025-06-28 04:50:53 +02:00
parent 65e9e4b5f7
commit bbb355ca70
Signed by: marc.beninca
GPG key ID: 9C7613450C80C24F

View file

@ -32,72 +32,24 @@ RWX_SELF_USER="${HOME}/${RWX_SELF_NAME}"
RWX_MAIN_PATH="${RWX_ROOT_SYSTEM}/${RWX_MAIN_NAME}"
# ╭──────┬──────╮
# │ main │ find
# │ main │ main
# ╰──────┴──────╯
# find directory’s files by extension
rwx_find_extension() {
local extension="${1}"
local root="${2}"
local file="${3}"
set -- \
"${root}" \
-name "*.${extension}" \
-type "f"
[ -n "${file}" ] &&
set -- "${@}" \
-not \
-name "${file}"
find "${@}" \
-printf "%P\n" |
sort
}
# find directory’s sh files
rwx_find_shell() {
rwx_find_extension "sh" "${@}"
}
# ╭──────┬─────╮
# │ main │ ifs │
# ╰──────┴─────╯
# set internal field separator to line feed
rwx_ifs_set() {
_RWX_IFS="${IFS}"
IFS="
"
}
# unset internal field separator
rwx_ifs_unset() {
IFS="${_RWX_IFS}"
unset RWX_IFS
}
# ╭──────┬───────╮
# │ main │ shell │
# ╰──────┴───────╯
# test if active shell is in interactive mode
rwx_shell_interactive() {
case "${-}" in
*i*) ;;
*) return 1 ;;
esac
}
# ╭──────┬─────╮
# │ main │ log │
# ╰──────┴─────╯
__rwx_log() {
if rwx_shell_interactive; then
[ ${#} -gt 0 ] || set -- ""
local line
for line in "${@}"; do
echo "${line}"
done
# run initial steps
rwx_main() {
# source system root
if ! rwx_source "${RWX_ROOT_SYSTEM}"; then
__rwx_log "Not a directory: ${RWX_ROOT_SYSTEM}"
return 1
fi
# source user root
rwx_source "${RWX_SELF_USER}"
# context / command
if [ -n "${RWX_COMMAND_NAME}" ]; then
"${RWX_SELF_COMMAND}${RWX_COMMAND_NAME}" "${@}"
# context / shell
else
rwx_self_init
fi
}
@ -125,26 +77,74 @@ rwx_source() {
rwx_ifs_unset
}
# ╭──────┬─────╮
# │ main │ log │
# ╰──────┴─────╯
__rwx_log() {
if rwx_shell_interactive; then
[ ${#} -gt 0 ] || set -- ""
local line
for line in "${@}"; do
echo "${line}"
done
fi
}
# ╭──────┬───────╮
# │ main │ shell │
# ╰──────┴───────╯
# test if active shell is in interactive mode
rwx_shell_interactive() {
case "${-}" in
*i*) ;;
*) return 1 ;;
esac
}
# ╭──────┬─────╮
# │ main │ ifs │
# ╰──────┴─────╯
# set internal field separator to line feed
rwx_ifs_set() {
_RWX_IFS="${IFS}"
IFS="
"
}
# unset internal field separator
rwx_ifs_unset() {
IFS="${_RWX_IFS}"
unset RWX_IFS
}
# ╭──────┬──────╮
# │ main │ main │
# │ main │ find
# ╰──────┴──────╯
# run initial steps
rwx_main() {
# source system root
if ! rwx_source "${RWX_ROOT_SYSTEM}"; then
__rwx_log "Not a directory: ${RWX_ROOT_SYSTEM}"
return 1
fi
# source user root
rwx_source "${RWX_SELF_USER}"
# context / command
if [ -n "${RWX_COMMAND_NAME}" ]; then
"${RWX_SELF_COMMAND}${RWX_COMMAND_NAME}" "${@}"
# context / shell
else
rwx_self_init
fi
# find directory’s files by extension
rwx_find_extension() {
local extension="${1}"
local root="${2}"
local file="${3}"
set -- \
"${root}" \
-name "*.${extension}" \
-type "f"
[ -n "${file}" ] &&
set -- "${@}" \
-not \
-name "${file}"
find "${@}" \
-printf "%P\n" |
sort
}
# find directory’s sh files
rwx_find_shell() {
rwx_find_extension "sh" "${@}"
}
# ╭──────┬─────╮