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}" RWX_MAIN_PATH="${RWX_ROOT_SYSTEM}/${RWX_MAIN_NAME}"
# ╭──────┬──────╮ # ╭──────┬──────╮
# │ main │ find # │ main │ main
# ╰──────┴──────╯ # ╰──────┴──────╯
# find directory’s files by extension # run initial steps
rwx_find_extension() { rwx_main() {
local extension="${1}" # source system root
local root="${2}" if ! rwx_source "${RWX_ROOT_SYSTEM}"; then
local file="${3}" __rwx_log "Not a directory: ${RWX_ROOT_SYSTEM}"
set -- \ return 1
"${root}" \ fi
-name "*.${extension}" \ # source user root
-type "f" rwx_source "${RWX_SELF_USER}"
[ -n "${file}" ] && # context / command
set -- "${@}" \ if [ -n "${RWX_COMMAND_NAME}" ]; then
-not \ "${RWX_SELF_COMMAND}${RWX_COMMAND_NAME}" "${@}"
-name "${file}" # context / shell
find "${@}" \ else
-printf "%P\n" | rwx_self_init
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
fi fi
} }
@ -125,26 +77,74 @@ rwx_source() {
rwx_ifs_unset 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 # find directory’s files by extension
rwx_main() { rwx_find_extension() {
# source system root local extension="${1}"
if ! rwx_source "${RWX_ROOT_SYSTEM}"; then local root="${2}"
__rwx_log "Not a directory: ${RWX_ROOT_SYSTEM}" local file="${3}"
return 1 set -- \
fi "${root}" \
# source user root -name "*.${extension}" \
rwx_source "${RWX_SELF_USER}" -type "f"
# context / command [ -n "${file}" ] &&
if [ -n "${RWX_COMMAND_NAME}" ]; then set -- "${@}" \
"${RWX_SELF_COMMAND}${RWX_COMMAND_NAME}" "${@}" -not \
# context / shell -name "${file}"
else find "${@}" \
rwx_self_init -printf "%P\n" |
fi sort
}
# find directory’s sh files
rwx_find_shell() {
rwx_find_extension "sh" "${@}"
} }
# ╭──────┬─────╮ # ╭──────┬─────╮