Compare commits

..

6 commits

Author SHA1 Message Date
62b3a9264b
−useless
All checks were successful
/ job (push) Successful in 4m56s
2025-07-07 04:34:57 +02:00
0b924b1ddf
main/function 2025-07-07 04:29:55 +02:00
0761ae6020
alias/function 2025-07-07 04:23:21 +02:00
47ff6043d5
install/while 2025-07-07 04:02:44 +02:00
e57b963f25
code/install 2025-07-07 03:51:14 +02:00
60ccba2fd5
−self/commands 2025-07-07 03:47:55 +02:00
3 changed files with 62 additions and 57 deletions

View file

@ -19,6 +19,45 @@ _rwx_code_functions=""
# cache for code variables # cache for code variables
_rwx_code_variables="" _rwx_code_variables=""
# ╭──────┬─────────╮
# │ code │ install │
# ╰──────┴─────────╯
#= rwx_install
rwx_code_install() {
local target="${1}"
local command file name root
# 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"
name="${RWX_SELF_NAME}.sh"
file="${root}/${name}"
rwx_remove "${file}"
rwx_link "${file}" "${RWX_MAIN_PATH}"
while IFS= read -r command; do
file="${root}/${command}"
rwx_remove "${file}"
rwx_link "${file}" "${name}"
done <<EOF
${_rwx_code_aliases}
EOF
# 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}"
}
# ╭──────┬───────╮ # ╭──────┬───────╮
# │ code │ parts │ # │ code │ parts │
# ╰──────┴───────╯ # ╰──────┴───────╯
@ -40,6 +79,21 @@ rwx_code_aliases() {
echo "${_rwx_code_aliases}" echo "${_rwx_code_aliases}"
} }
# find aliased function
rwx_code_alias_function() {
local target="${1}"
local line name
while IFS= read -r line; do
name="$(echo "${line}" | awk "{print \$1}")"
if [ "${name}" = "${target}" ]; then
echo "${line}" |
awk "{print \$2}"
fi
done <<EOF
${_rwx_code_aliases_functions}
EOF
}
# show the cached aliases and functions # show the cached aliases and functions
#= rcaf #= rcaf
rwx_code_aliases_functions() { rwx_code_aliases_functions() {

View file

@ -22,9 +22,6 @@ RWX_MAIN_NAME="main.sh"
# name of the project itself # name of the project itself
RWX_SELF_NAME="rwx" RWX_SELF_NAME="rwx"
# prefix for command functions
RWX_SELF_COMMAND="_${RWX_SELF_NAME}_cmd_"
# ╭──────┬───────────╮ # ╭──────┬───────────╮
# │ main │ variables │ # │ main │ variables │
# ╰──────┴───────────╯ # ╰──────┴───────────╯
@ -67,7 +64,11 @@ rwx_main() {
rwx_code_load rwx_code_load
# context / command # context / command
if [ -n "${RWX_COMMAND_NAME}" ]; then if [ -n "${RWX_COMMAND_NAME}" ]; then
"${RWX_SELF_COMMAND}${RWX_COMMAND_NAME}" "${@}" local function
function="$(rwx_code_alias_function "${RWX_COMMAND_NAME}")"
if [ -n "${function}" ]; then
"${function}" "${@}"
fi
# context / shell # context / shell
else else
rwx_self_init rwx_self_init

View file

@ -1,19 +1,6 @@
# self # ╭──────╮
# module # │ self │
# ╰──────╯
# ╭──────┬──────────╮
# │ 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 │ help │ # │ self │ help │
@ -40,43 +27,6 @@ rwx_self_init() {
fi fi
} }
# ╭──────┬─────────╮
# │ self │ install │
# ╰──────┴─────────╯
_rwx_cmd_rwx_install() { rwx_self_install "${@}"; }
rwx_self_install() {
local target="${1}"
local command file name root
# 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"
name="${RWX_SELF_NAME}.sh"
file="${root}/${name}"
rwx_remove "${file}"
rwx_link "${file}" "${RWX_MAIN_PATH}"
for command in $(rwx_self_commands); do
file="${root}/${command}"
rwx_remove "${file}"
rwx_link "${file}" "${name}"
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 │ # │ self │ subset │
# ╰──────┴────────╯ # ╰──────┴────────╯