2025-07-06 03:16:41 +02:00
|
|
|
# self
|
|
|
|
# module
|
2025-07-04 03:35:51 +02:00
|
|
|
|
2025-07-06 10:30:24 +02:00
|
|
|
# show the cached code
|
|
|
|
#= rc
|
|
|
|
rwx_code() {
|
2025-07-06 16:02:10 +02:00
|
|
|
echo "${_rwx_code}"
|
2025-07-06 10:30:24 +02:00
|
|
|
}
|
|
|
|
|
2025-07-06 11:02:50 +02:00
|
|
|
# show the cached aliases
|
|
|
|
#= rca
|
|
|
|
rwx_code_aliases() {
|
2025-07-06 16:02:10 +02:00
|
|
|
echo "${RWX_ALIASES}"
|
2025-07-06 11:02:50 +02:00
|
|
|
}
|
|
|
|
|
2025-07-06 10:30:24 +02:00
|
|
|
# show the cached constants
|
|
|
|
#= rcc
|
|
|
|
rwx_code_constants() {
|
2025-07-06 16:02:10 +02:00
|
|
|
echo "${RWX_CONSTANTS}"
|
2025-07-06 10:30:24 +02:00
|
|
|
}
|
|
|
|
|
2025-07-06 11:02:50 +02:00
|
|
|
# show the cached functions
|
|
|
|
#= rcf
|
|
|
|
rwx_code_functions() {
|
2025-07-06 16:02:10 +02:00
|
|
|
echo "${RWX_FUNCTIONS}"
|
2025-07-06 11:02:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# show the cached variables
|
|
|
|
#= rcv
|
|
|
|
rwx_code_variables() {
|
2025-07-06 16:02:10 +02:00
|
|
|
echo "${_rwx_code_variables}"
|
2025-07-06 11:02:50 +02:00
|
|
|
}
|
|
|
|
|
2025-02-10 21:54:51 +01:00
|
|
|
# meta doc
|
2025-07-06 10:30:24 +02:00
|
|
|
#= rd
|
2025-02-10 21:54:51 +01:00
|
|
|
rwx_doc() {
|
2025-07-06 00:12:37 +02:00
|
|
|
local name="${1}"
|
|
|
|
[ -n "${name}" ] || return
|
2025-07-06 05:59:23 +02:00
|
|
|
printf "%s" "${_rwx_code}" |
|
2025-07-06 00:12:37 +02:00
|
|
|
awk \
|
2025-07-06 06:41:44 +02:00
|
|
|
--assign action="doc" \
|
2025-07-06 06:08:39 +02:00
|
|
|
--assign target="${name}" \
|
|
|
|
--file "${RWX_AWK}"
|
2025-07-06 00:12:37 +02:00
|
|
|
}
|
|
|
|
|
2025-02-10 21:54:51 +01:00
|
|
|
# ╭──────┬───────╮
|
|
|
|
# │ self │ check │
|
|
|
|
# ╰──────┴───────╯
|
|
|
|
|
|
|
|
# check source code
|
|
|
|
rwx_self_check() {
|
|
|
|
# check format
|
|
|
|
rwx_log
|
|
|
|
rwx_shfmt "${RWX_ROOT_SYSTEM}"
|
|
|
|
# check syntax
|
|
|
|
rwx_log
|
|
|
|
rwx_shellcheck "${RWX_ROOT_SYSTEM}"
|
|
|
|
}
|
|
|
|
|
|
|
|
# ╭──────┬──────────╮
|
|
|
|
# │ self │ commands │
|
|
|
|
# ╰──────┴──────────╯
|
|
|
|
|
|
|
|
# get commands from root
|
|
|
|
rwx_self_commands() {
|
|
|
|
grep \
|
|
|
|
--directories "recurse" \
|
|
|
|
--no-filename \
|
|
|
|
"^${RWX_SELF_COMMAND}" "${RWX_ROOT_SYSTEM}" |
|
|
|
|
cut --delimiter "(" --fields 1 |
|
|
|
|
sed "s|^${RWX_SELF_COMMAND}||"
|
|
|
|
}
|
|
|
|
|
|
|
|
# ╭──────┬───────────╮
|
|
|
|
# │ self │ functions │
|
|
|
|
# ╰──────┴───────────╯
|
|
|
|
|
|
|
|
# get functions from root
|
|
|
|
rwx_self_functions() {
|
|
|
|
grep \
|
|
|
|
--directories "recurse" \
|
|
|
|
--no-filename \
|
|
|
|
"()" "${RWX_ROOT_SYSTEM}" |
|
|
|
|
cut --delimiter "(" --fields 1
|
|
|
|
}
|
|
|
|
|
|
|
|
# ╭──────┬──────╮
|
|
|
|
# │ 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 │ install │
|
|
|
|
# ╰──────┴─────────╯
|
|
|
|
|
|
|
|
_rwx_cmd_rwx_install() { rwx_self_install "${@}"; }
|
|
|
|
rwx_self_install() {
|
|
|
|
local target="${1}"
|
2025-06-28 03:01:52 +02:00
|
|
|
local command file name root
|
2025-02-10 21:54:51 +01:00
|
|
|
# code
|
|
|
|
if [ -n "${target}" ]; then
|
|
|
|
root="${target}${RWX_ROOT_SYSTEM}"
|
|
|
|
rwx_remove "${root}"
|
|
|
|
cp --recursive "${RWX_ROOT_SYSTEM}" "${root}"
|
|
|
|
fi
|
|
|
|
# commands
|
|
|
|
root="${target}/usr/local/bin"
|
2025-06-28 03:01:52 +02:00
|
|
|
name="${RWX_SELF_NAME}.sh"
|
|
|
|
file="${root}/${name}"
|
|
|
|
rwx_remove "${file}"
|
|
|
|
rwx_link "${file}" "${RWX_MAIN_PATH}"
|
2025-02-10 21:54:51 +01:00
|
|
|
for command in $(rwx_self_commands); do
|
|
|
|
file="${root}/${command}"
|
|
|
|
rwx_remove "${file}"
|
2025-06-28 03:01:52 +02:00
|
|
|
rwx_link "${file}" "${name}"
|
2025-02-10 21:54:51 +01:00
|
|
|
done
|
|
|
|
# sh
|
|
|
|
file="${target}/etc/profile.d/${RWX_SELF_NAME}.sh"
|
|
|
|
rwx_remove "${file}"
|
|
|
|
rwx_file_write "${file}" "\
|
|
|
|
export ENV=\"${RWX_MAIN_PATH}\"
|
|
|
|
"
|
|
|
|
# bash
|
|
|
|
file="${target}/etc/bash.bashrc"
|
|
|
|
rwx_remove "${file}"
|
|
|
|
rwx_link "${file}" "${RWX_MAIN_PATH}"
|
|
|
|
}
|
|
|
|
|
|
|
|
# ╭──────┬────────╮
|
|
|
|
# │ 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
|
|
|
|
}
|