Compare commits
No commits in common. "091c9339f70b428eab746f315648c9e099ef7473" and "aec3d1a0afe49b5065e75040e2be11aec7076876" have entirely different histories.
091c9339f7
...
aec3d1a0af
6 changed files with 127 additions and 164 deletions
18
sh/alias/shell.sh
Normal file
18
sh/alias/shell.sh
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
# shorten alias
|
||||||
|
a() {
|
||||||
|
alias \
|
||||||
|
"${@}"
|
||||||
|
}
|
||||||
|
|
||||||
|
# swap directory (current ↔ previous)
|
||||||
|
sd() {
|
||||||
|
cd \
|
||||||
|
- ||
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
# exit terminal
|
||||||
|
x() {
|
||||||
|
exit \
|
||||||
|
"${@}"
|
||||||
|
}
|
14
sh/code.awk
14
sh/code.awk
|
@ -32,7 +32,6 @@ BEGIN {
|
||||||
|
|
||||||
RE_ALIAS = RE_BEGIN "#=" RE_SPACES RE_VAR RE_END
|
RE_ALIAS = RE_BEGIN "#=" RE_SPACES RE_VAR RE_END
|
||||||
RE_CLOSE = RE_BEGIN "}" RE_SPACES RE_END
|
RE_CLOSE = RE_BEGIN "}" RE_SPACES RE_END
|
||||||
RE_COMMAND = RE_BEGIN "#/" RE_SPACES RE_VAR RE_END
|
|
||||||
RE_CONSTANT = RE_BEGIN RE_CONST RE_SET RE_END
|
RE_CONSTANT = RE_BEGIN RE_CONST RE_SET RE_END
|
||||||
RE_DOC = RE_BEGIN RE_SPACES "#" RE_SPACE RE_ANY RE_END
|
RE_DOC = RE_BEGIN RE_SPACES "#" RE_SPACE RE_ANY RE_END
|
||||||
RE_FUNCTION = RE_BEGIN RE_VAR RE_FUNC RE_END
|
RE_FUNCTION = RE_BEGIN RE_VAR RE_FUNC RE_END
|
||||||
|
@ -41,7 +40,6 @@ BEGIN {
|
||||||
RE_VARIABLE = RE_BEGIN RE_VAR RE_SET RE_END
|
RE_VARIABLE = RE_BEGIN RE_VAR RE_SET RE_END
|
||||||
|
|
||||||
alias = 0
|
alias = 0
|
||||||
command = 0
|
|
||||||
f = ""
|
f = ""
|
||||||
reset()
|
reset()
|
||||||
module = 0
|
module = 0
|
||||||
|
@ -52,10 +50,6 @@ BEGIN {
|
||||||
if (match($0, RE_ALIAS, m)) {
|
if (match($0, RE_ALIAS, m)) {
|
||||||
print m[1]
|
print m[1]
|
||||||
}
|
}
|
||||||
} else if (action == "commands") {
|
|
||||||
if (match($0, RE_COMMAND, m)) {
|
|
||||||
print m[1]
|
|
||||||
}
|
|
||||||
} else if (action == "constants") {
|
} else if (action == "constants") {
|
||||||
if (match($0, RE_CONSTANT, m)) {
|
if (match($0, RE_CONSTANT, m)) {
|
||||||
print m[1]
|
print m[1]
|
||||||
|
@ -95,11 +89,6 @@ BEGIN {
|
||||||
if (m[1] == target) {
|
if (m[1] == target) {
|
||||||
alias = 1
|
alias = 1
|
||||||
}
|
}
|
||||||
} else if (match($0, RE_COMMAND, m)) {
|
|
||||||
append("/ " m[1])
|
|
||||||
if (m[1] == target) {
|
|
||||||
command = 1
|
|
||||||
}
|
|
||||||
# set
|
# set
|
||||||
} else if (match($0, RE_CONSTANT, m)) {
|
} else if (match($0, RE_CONSTANT, m)) {
|
||||||
if (m[1] == target) {
|
if (m[1] == target) {
|
||||||
|
@ -125,9 +114,6 @@ BEGIN {
|
||||||
if (alias) {
|
if (alias) {
|
||||||
print "= " target
|
print "= " target
|
||||||
output(f, "function")
|
output(f, "function")
|
||||||
} else if (command) {
|
|
||||||
print "/ " target
|
|
||||||
output(f, "function")
|
|
||||||
} else if (f == target) {
|
} else if (f == target) {
|
||||||
output(f, "function")
|
output(f, "function")
|
||||||
} else {
|
} else {
|
||||||
|
|
13
sh/code.sh
13
sh/code.sh
|
@ -12,8 +12,6 @@ _rwx_code_awk="$(cat "${RWX_ROOT_SYSTEM}/code.awk")"
|
||||||
_rwx_code_aliases=""
|
_rwx_code_aliases=""
|
||||||
# cache for code aliases functions
|
# cache for code aliases functions
|
||||||
_rwx_code_aliases_functions=""
|
_rwx_code_aliases_functions=""
|
||||||
# cache for code commands
|
|
||||||
_rwx_code_commands=""
|
|
||||||
# cache for code constants
|
# cache for code constants
|
||||||
_rwx_code_constants=""
|
_rwx_code_constants=""
|
||||||
# cache for code functions
|
# cache for code functions
|
||||||
|
@ -25,7 +23,7 @@ _rwx_code_variables=""
|
||||||
# │ code │ install │
|
# │ code │ install │
|
||||||
# ╰──────┴─────────╯
|
# ╰──────┴─────────╯
|
||||||
|
|
||||||
#/ rwx_install
|
#= rwx_install
|
||||||
rwx_code_install() {
|
rwx_code_install() {
|
||||||
local target="${1}"
|
local target="${1}"
|
||||||
local command file name root
|
local command file name root
|
||||||
|
@ -46,7 +44,7 @@ rwx_code_install() {
|
||||||
rwx_remove "${file}"
|
rwx_remove "${file}"
|
||||||
rwx_link "${file}" "${name}"
|
rwx_link "${file}" "${name}"
|
||||||
done <<EOF
|
done <<EOF
|
||||||
${_rwx_code_commands}
|
${_rwx_code_aliases}
|
||||||
EOF
|
EOF
|
||||||
# sh
|
# sh
|
||||||
file="${target}/etc/profile.d/${RWX_SELF_NAME}.sh"
|
file="${target}/etc/profile.d/${RWX_SELF_NAME}.sh"
|
||||||
|
@ -102,11 +100,6 @@ rwx_code_aliases_functions() {
|
||||||
echo "${_rwx_code_aliases_functions}"
|
echo "${_rwx_code_aliases_functions}"
|
||||||
}
|
}
|
||||||
|
|
||||||
# show the cached commands
|
|
||||||
rwx_code_commands() {
|
|
||||||
echo "${_rwx_code_commands}"
|
|
||||||
}
|
|
||||||
|
|
||||||
# show the cached constants
|
# show the cached constants
|
||||||
#= rcc
|
#= rcc
|
||||||
rwx_code_constants() {
|
rwx_code_constants() {
|
||||||
|
@ -164,8 +157,6 @@ rwx_code_load() {
|
||||||
done <<EOF
|
done <<EOF
|
||||||
${_rwx_code_aliases_functions}
|
${_rwx_code_aliases_functions}
|
||||||
EOF
|
EOF
|
||||||
# parse commands
|
|
||||||
_rwx_code_commands="$(rwx_code_parse "commands")"
|
|
||||||
# parse constants
|
# parse constants
|
||||||
_rwx_code_constants="$(rwx_code_parse "constants")"
|
_rwx_code_constants="$(rwx_code_parse "constants")"
|
||||||
# parse functions
|
# parse functions
|
||||||
|
|
210
sh/main.sh
210
sh/main.sh
|
@ -26,8 +26,8 @@ RWX_SELF_NAME="rwx"
|
||||||
# │ main │ variables │
|
# │ main │ variables │
|
||||||
# ╰──────┴───────────╯
|
# ╰──────┴───────────╯
|
||||||
|
|
||||||
# cache of all sourced code modules
|
# currently running shell name
|
||||||
_rwx_code=""
|
RWX_SHELL="$(cat "/proc/${$}/comm")"
|
||||||
|
|
||||||
# system root directory of the project
|
# system root directory of the project
|
||||||
RWX_ROOT_SYSTEM="/usr/local/lib/${RWX_SELF_NAME}"
|
RWX_ROOT_SYSTEM="/usr/local/lib/${RWX_SELF_NAME}"
|
||||||
|
@ -37,109 +37,6 @@ RWX_SELF_USER="${HOME}/${RWX_SELF_NAME}"
|
||||||
# path to the entrypoint main file of the project
|
# path to the entrypoint main file of the project
|
||||||
RWX_MAIN_PATH="${RWX_ROOT_SYSTEM}/${RWX_MAIN_NAME}"
|
RWX_MAIN_PATH="${RWX_ROOT_SYSTEM}/${RWX_MAIN_NAME}"
|
||||||
|
|
||||||
# ╭──────┬──────╮
|
|
||||||
# │ main │ find │
|
|
||||||
# ╰──────┴──────╯
|
|
||||||
|
|
||||||
# find directory’s files by extension
|
|
||||||
#> find
|
|
||||||
#> sort
|
|
||||||
rwx_find_extension() {
|
|
||||||
local extension="${1}"
|
|
||||||
local root="${2}"
|
|
||||||
local file="${3}"
|
|
||||||
set -- \
|
|
||||||
"${root}" \
|
|
||||||
-name "*.${extension}" \
|
|
||||||
-type "f"
|
|
||||||
[ -n "${file}" ] &&
|
|
||||||
set -- "${@}" \
|
|
||||||
-not \
|
|
||||||
-name "${file}"
|
|
||||||
find "${@}" \
|
|
||||||
-printf "%P\n" |
|
|
||||||
sort
|
|
||||||
}
|
|
||||||
|
|
||||||
# find directory’s sh files
|
|
||||||
rwx_find_shell() {
|
|
||||||
rwx_find_extension "sh" "${@}"
|
|
||||||
}
|
|
||||||
|
|
||||||
# ╭──────┬───────╮
|
|
||||||
# │ main │ shell │
|
|
||||||
# ╰──────┴───────╯
|
|
||||||
|
|
||||||
# test if active shell is in interactive mode
|
|
||||||
rwx_shell_interactive() {
|
|
||||||
case "${-}" in
|
|
||||||
*i*) ;;
|
|
||||||
*) return 1 ;;
|
|
||||||
esac
|
|
||||||
}
|
|
||||||
|
|
||||||
# ╭──────┬─────╮
|
|
||||||
# │ main │ log │
|
|
||||||
# ╰──────┴─────╯
|
|
||||||
|
|
||||||
__rwx_log() {
|
|
||||||
if rwx_shell_interactive; then
|
|
||||||
[ ${#} -gt 0 ] || set -- ""
|
|
||||||
local line
|
|
||||||
for line in "${@}"; do
|
|
||||||
echo "${line}"
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# ╭──────┬────────╮
|
|
||||||
# │ main │ source │
|
|
||||||
# ╰──────┴────────╯
|
|
||||||
|
|
||||||
# source code from file path
|
|
||||||
rwx_source() {
|
|
||||||
local root="${1}"
|
|
||||||
[ -d "${root}" ] ||
|
|
||||||
return 1
|
|
||||||
local file="${2}"
|
|
||||||
local count module modules
|
|
||||||
count=0
|
|
||||||
__rwx_log "" \
|
|
||||||
". ${root}"
|
|
||||||
modules="$(rwx_find_shell "${root}" "${file}")"
|
|
||||||
while IFS= read -r module; do
|
|
||||||
count=$((count + 1))
|
|
||||||
__rwx_log "$(printf "%02d" "${count}") ${module%.sh}"
|
|
||||||
# shellcheck disable=SC1090
|
|
||||||
. "${root}/${module}"
|
|
||||||
# cache code
|
|
||||||
rwx_cache "${root}" "${module}"
|
|
||||||
done <<EOF
|
|
||||||
${modules}
|
|
||||||
EOF
|
|
||||||
}
|
|
||||||
|
|
||||||
# ╭──────┬───────╮
|
|
||||||
# │ main │ cache │
|
|
||||||
# ╰──────┴───────╯
|
|
||||||
|
|
||||||
# cache source code of a module
|
|
||||||
# inside a global code variable
|
|
||||||
#> cat
|
|
||||||
rwx_cache() {
|
|
||||||
local root="${1}"
|
|
||||||
local module="${2}"
|
|
||||||
local name="${module%.sh}"
|
|
||||||
local path="${root}/${module}"
|
|
||||||
local text
|
|
||||||
text="$(cat "${path}")"
|
|
||||||
# all source code
|
|
||||||
_rwx_code="${_rwx_code}\
|
|
||||||
#. ${name}
|
|
||||||
${text}
|
|
||||||
"
|
|
||||||
}
|
|
||||||
|
|
||||||
# ╭──────┬──────╮
|
# ╭──────┬──────╮
|
||||||
# │ main │ main │
|
# │ main │ main │
|
||||||
# ╰──────┴──────╯
|
# ╰──────┴──────╯
|
||||||
|
@ -179,6 +76,109 @@ rwx_main() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# ╭──────┬───────╮
|
||||||
|
# │ main │ cache │
|
||||||
|
# ╰──────┴───────╯
|
||||||
|
|
||||||
|
# cache of all sourced code modules
|
||||||
|
_rwx_code=""
|
||||||
|
|
||||||
|
# cache source code of a module
|
||||||
|
# inside a global code variable
|
||||||
|
rwx_cache() {
|
||||||
|
local root="${1}"
|
||||||
|
local module="${2}"
|
||||||
|
local name="${module%.sh}"
|
||||||
|
local path="${root}/${module}"
|
||||||
|
local text
|
||||||
|
text="$(cat "${path}")"
|
||||||
|
# all source code
|
||||||
|
_rwx_code="${_rwx_code}\
|
||||||
|
#. ${name}
|
||||||
|
${text}
|
||||||
|
"
|
||||||
|
}
|
||||||
|
|
||||||
|
# ╭──────┬────────╮
|
||||||
|
# │ main │ source │
|
||||||
|
# ╰──────┴────────╯
|
||||||
|
|
||||||
|
# source code from file path
|
||||||
|
rwx_source() {
|
||||||
|
local root="${1}"
|
||||||
|
[ -d "${root}" ] ||
|
||||||
|
return 1
|
||||||
|
local file="${2}"
|
||||||
|
local count module modules
|
||||||
|
count=0
|
||||||
|
__rwx_log "" \
|
||||||
|
". ${root}"
|
||||||
|
modules="$(rwx_find_shell "${root}" "${file}")"
|
||||||
|
while IFS= read -r module; do
|
||||||
|
count=$((count + 1))
|
||||||
|
__rwx_log "$(printf "%02d" "${count}") ${module%.sh}"
|
||||||
|
# shellcheck disable=SC1090
|
||||||
|
. "${root}/${module}"
|
||||||
|
# cache code
|
||||||
|
rwx_cache "${root}" "${module}"
|
||||||
|
done <<EOF
|
||||||
|
${modules}
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
|
# ╭──────┬─────╮
|
||||||
|
# │ main │ log │
|
||||||
|
# ╰──────┴─────╯
|
||||||
|
|
||||||
|
__rwx_log() {
|
||||||
|
if rwx_shell_interactive; then
|
||||||
|
[ ${#} -gt 0 ] || set -- ""
|
||||||
|
local line
|
||||||
|
for line in "${@}"; do
|
||||||
|
echo "${line}"
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# ╭──────┬───────╮
|
||||||
|
# │ main │ shell │
|
||||||
|
# ╰──────┴───────╯
|
||||||
|
|
||||||
|
# test if active shell is in interactive mode
|
||||||
|
rwx_shell_interactive() {
|
||||||
|
case "${-}" in
|
||||||
|
*i*) ;;
|
||||||
|
*) return 1 ;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
# ╭──────┬──────╮
|
||||||
|
# │ main │ find │
|
||||||
|
# ╰──────┴──────╯
|
||||||
|
|
||||||
|
# find directory’s files by extension
|
||||||
|
rwx_find_extension() {
|
||||||
|
local extension="${1}"
|
||||||
|
local root="${2}"
|
||||||
|
local file="${3}"
|
||||||
|
set -- \
|
||||||
|
"${root}" \
|
||||||
|
-name "*.${extension}" \
|
||||||
|
-type "f"
|
||||||
|
[ -n "${file}" ] &&
|
||||||
|
set -- "${@}" \
|
||||||
|
-not \
|
||||||
|
-name "${file}"
|
||||||
|
find "${@}" \
|
||||||
|
-printf "%P\n" |
|
||||||
|
sort
|
||||||
|
}
|
||||||
|
|
||||||
|
# find directory’s sh files
|
||||||
|
rwx_find_shell() {
|
||||||
|
rwx_find_extension "sh" "${@}"
|
||||||
|
}
|
||||||
|
|
||||||
# ╭──────┬─────╮
|
# ╭──────┬─────╮
|
||||||
# │ main │ run │
|
# │ main │ run │
|
||||||
# ╰──────┴─────╯
|
# ╰──────┴─────╯
|
||||||
|
|
|
@ -2,9 +2,6 @@
|
||||||
# │ shell │
|
# │ shell │
|
||||||
# ╰───────╯
|
# ╰───────╯
|
||||||
|
|
||||||
# currently running shell name
|
|
||||||
RWX_SHELL="$(cat "/proc/${$}/comm")"
|
|
||||||
|
|
||||||
_rwx_shell_color() {
|
_rwx_shell_color() {
|
||||||
local code="${1}"
|
local code="${1}"
|
||||||
case "${RWX_SHELL}" in
|
case "${RWX_SHELL}" in
|
||||||
|
@ -130,32 +127,6 @@ rwx_shell_prompt() {
|
||||||
printf "%b" "${view}"
|
printf "%b" "${view}"
|
||||||
}
|
}
|
||||||
|
|
||||||
# ╭───────┬───────────╮
|
|
||||||
# │ shell │ shortcuts │
|
|
||||||
# ╰───────┴───────────╯
|
|
||||||
|
|
||||||
# shorten alias
|
|
||||||
#= a
|
|
||||||
rwx_shell_alias() {
|
|
||||||
alias \
|
|
||||||
"${@}"
|
|
||||||
}
|
|
||||||
|
|
||||||
# swap directory (current ↔ previous)
|
|
||||||
#= sd
|
|
||||||
rwx_shell_swap_directory() {
|
|
||||||
cd \
|
|
||||||
- ||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
# exit terminal
|
|
||||||
#= x
|
|
||||||
rwx_shell_exit() {
|
|
||||||
exit \
|
|
||||||
"${@}"
|
|
||||||
}
|
|
||||||
|
|
||||||
# ╭───────┬──────╮
|
# ╭───────┬──────╮
|
||||||
# │ shell │ main │
|
# │ shell │ main │
|
||||||
# ╰───────┴──────╯
|
# ╰───────┴──────╯
|
||||||
|
|
|
@ -21,8 +21,7 @@ rwx_test_code() {
|
||||||
"variables" \
|
"variables" \
|
||||||
"functions" \
|
"functions" \
|
||||||
"aliases" \
|
"aliases" \
|
||||||
"aliases_functions" \
|
"aliases_functions"
|
||||||
"commands"
|
|
||||||
rwx_code
|
rwx_code
|
||||||
for items in "${@}"; do
|
for items in "${@}"; do
|
||||||
echo
|
echo
|
||||||
|
@ -47,9 +46,7 @@ rwx_test_doc() {
|
||||||
"rwx_cache" \
|
"rwx_cache" \
|
||||||
\
|
\
|
||||||
"alias/batcat" \
|
"alias/batcat" \
|
||||||
"b" \
|
"b"
|
||||||
\
|
|
||||||
"rwx_install"
|
|
||||||
for item in "${@}"; do
|
for item in "${@}"; do
|
||||||
echo
|
echo
|
||||||
rwx_code_doc "${item}"
|
rwx_code_doc "${item}"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue