2025-07-07 03:47:55 +02:00
|
|
|
# ╭──────╮
|
|
|
|
# │ self │
|
|
|
|
# ╰──────╯
|
2025-02-10 21:54:51 +01:00
|
|
|
|
|
|
|
# ╭──────┬──────╮
|
|
|
|
# │ self │ help │
|
|
|
|
# ╰──────┴──────╯
|
|
|
|
|
|
|
|
# output help message
|
|
|
|
rwx_self_help() {
|
|
|
|
rwx_log \
|
|
|
|
"rwx_… = functions" \
|
|
|
|
" a__… = aliases" \
|
|
|
|
" u__… = user"
|
|
|
|
}
|
|
|
|
|
|
|
|
# ╭──────┬──────╮
|
|
|
|
# │ self │ init │
|
|
|
|
# ╰──────┴──────╯
|
|
|
|
|
|
|
|
rwx_self_init() {
|
|
|
|
# run interactive extras
|
|
|
|
if rwx_shell_interactive; then
|
|
|
|
# help
|
|
|
|
rwx_log
|
|
|
|
rwx_self_help
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# ╭──────┬────────╮
|
|
|
|
# │ self │ subset │
|
|
|
|
# ╰──────┴────────╯
|
|
|
|
|
|
|
|
rwx_self_subset() {
|
2025-07-04 04:53:46 +02:00
|
|
|
local argument file root
|
2025-02-10 21:54:51 +01:00
|
|
|
for argument in "${@}"; do
|
2025-07-04 04:53:46 +02:00
|
|
|
root="${RWX_ROOT_SYSTEM}/${argument}"
|
|
|
|
file="${argument}.sh"
|
|
|
|
if [ -d "${root}" ]; then
|
2025-02-10 21:54:51 +01:00
|
|
|
local file
|
2025-07-04 04:53:46 +02:00
|
|
|
for file in $(rwx_find_shell "${root}"); do
|
2025-02-10 21:54:51 +01:00
|
|
|
echo "${argument}/${file}"
|
|
|
|
done
|
2025-07-04 04:53:46 +02:00
|
|
|
elif [ -f "${RWX_ROOT_SYSTEM}/${file}" ]; then
|
|
|
|
echo "${file}"
|
2025-02-10 21:54:51 +01:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
# ╭──────┬───────╮
|
|
|
|
# │ self │ write │
|
|
|
|
# ╰──────┴───────╯
|
|
|
|
|
|
|
|
rwx_self_write() {
|
|
|
|
local target="${1}"
|
|
|
|
if [ -n "${target}" ]; then
|
|
|
|
shift
|
2025-07-06 16:03:46 +02:00
|
|
|
local file files text
|
2025-02-10 21:54:51 +01:00
|
|
|
text="#! /usr/bin/env sh
|
|
|
|
"
|
2025-07-06 16:03:46 +02:00
|
|
|
files="$(rwx_self_subset "${@}")"
|
2025-07-04 05:10:44 +02:00
|
|
|
while IFS= read -r file; do
|
2025-02-10 21:54:51 +01:00
|
|
|
text="${text}
|
|
|
|
$(cat "${RWX_ROOT_SYSTEM}/${file}")
|
|
|
|
"
|
2025-07-04 05:10:44 +02:00
|
|
|
done <<EOF
|
|
|
|
${files}
|
|
|
|
EOF
|
2025-02-10 21:54:51 +01:00
|
|
|
rwx_file_write "${target}" "${text}"
|
|
|
|
rwx_shfmt "${target}"
|
|
|
|
rwx_shellcheck_file "${target}"
|
|
|
|
fi
|
|
|
|
}
|