rwx/sh/self.sh

51 lines
1.1 KiB
Bash
Raw Normal View History

2025-07-07 03:47:55 +02:00
# ╭──────╮
# │ self │
# ╰──────╯
# ╭──────┬────────╮
# │ self │ subset │
# ╰──────┴────────╯
2025-07-08 06:09:14 +02:00
# TODO move to code module
rwx_self_subset() {
2025-07-04 04:53:46 +02:00
local argument file root
for argument in "${@}"; do
2025-07-04 04:53:46 +02:00
root="${RWX_ROOT_SYSTEM}/${argument}"
file="${argument}.sh"
if [ -d "${root}" ]; then
local file
2025-07-04 04:53:46 +02:00
for file in $(rwx_find_shell "${root}"); do
echo "${argument}/${file}"
done
2025-07-04 04:53:46 +02:00
elif [ -f "${RWX_ROOT_SYSTEM}/${file}" ]; then
echo "${file}"
fi
done
}
# ╭──────┬───────╮
# │ self │ write │
# ╰──────┴───────╯
2025-07-08 06:09:14 +02:00
# TODO move to code module
rwx_self_write() {
local target="${1}"
if [ -n "${target}" ]; then
shift
2025-07-06 16:03:46 +02:00
local file files text
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
text="${text}
$(cat "${RWX_ROOT_SYSTEM}/${file}")
"
2025-07-04 05:10:44 +02:00
done <<EOF
${files}
EOF
rwx_file_write "${target}" "${text}"
rwx_shfmt "${target}"
rwx_shellcheck_file "${target}"
fi
}