Compare commits
No commits in common. "62b3a9264b150f7040d5b53690d4acf349b840b9" and "950f54ecdc1006b3bb26aa500fb6bdc1dd352a20" have entirely different histories.
62b3a9264b
...
950f54ecdc
3 changed files with 57 additions and 62 deletions
54
sh/code.sh
54
sh/code.sh
|
@ -19,45 +19,6 @@ _rwx_code_functions=""
|
|||
# cache for 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 │
|
||||
# ╰──────┴───────╯
|
||||
|
@ -79,21 +40,6 @@ 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
|
||||
#= rcaf
|
||||
rwx_code_aliases_functions() {
|
||||
|
|
|
@ -22,6 +22,9 @@ RWX_MAIN_NAME="main.sh"
|
|||
# name of the project itself
|
||||
RWX_SELF_NAME="rwx"
|
||||
|
||||
# prefix for command functions
|
||||
RWX_SELF_COMMAND="_${RWX_SELF_NAME}_cmd_"
|
||||
|
||||
# ╭──────┬───────────╮
|
||||
# │ main │ variables │
|
||||
# ╰──────┴───────────╯
|
||||
|
@ -64,11 +67,7 @@ rwx_main() {
|
|||
rwx_code_load
|
||||
# context / command
|
||||
if [ -n "${RWX_COMMAND_NAME}" ]; then
|
||||
local function
|
||||
function="$(rwx_code_alias_function "${RWX_COMMAND_NAME}")"
|
||||
if [ -n "${function}" ]; then
|
||||
"${function}" "${@}"
|
||||
fi
|
||||
"${RWX_SELF_COMMAND}${RWX_COMMAND_NAME}" "${@}"
|
||||
# context / shell
|
||||
else
|
||||
rwx_self_init
|
||||
|
|
56
sh/self.sh
56
sh/self.sh
|
@ -1,6 +1,19 @@
|
|||
# ╭──────╮
|
||||
# │ self │
|
||||
# ╰──────╯
|
||||
# self
|
||||
# module
|
||||
|
||||
# ╭──────┬──────────╮
|
||||
# │ 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 │
|
||||
|
@ -27,6 +40,43 @@ rwx_self_init() {
|
|||
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 │
|
||||
# ╰──────┴────────╯
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue