Compare commits
6 commits
950f54ecdc
...
62b3a9264b
Author | SHA1 | Date | |
---|---|---|---|
62b3a9264b | |||
0b924b1ddf | |||
0761ae6020 | |||
47ff6043d5 | |||
e57b963f25 | |||
60ccba2fd5 |
3 changed files with 62 additions and 57 deletions
54
sh/code.sh
54
sh/code.sh
|
@ -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() {
|
||||||
|
|
|
@ -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
|
||||||
|
|
56
sh/self.sh
56
sh/self.sh
|
@ -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 │
|
||||||
# ╰──────┴────────╯
|
# ╰──────┴────────╯
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue