Compare commits
5 commits
a3ea2e6ef0
...
967e17e224
Author | SHA1 | Date | |
---|---|---|---|
967e17e224 | |||
3b222fda83 | |||
9b61976835 | |||
0926d058f5 | |||
b108ace00a |
3 changed files with 73 additions and 6 deletions
25
sh/code.awk
25
sh/code.awk
|
@ -31,6 +31,7 @@ BEGIN {
|
||||||
RE_FUNC = RE_SPACES "\\(" RE_SPACES "\\)" RE_SPACES "{"
|
RE_FUNC = RE_SPACES "\\(" RE_SPACES "\\)" RE_SPACES "{"
|
||||||
|
|
||||||
RE_ALIAS = RE_BEGIN "#=" RE_SPACES RE_VAR RE_END
|
RE_ALIAS = RE_BEGIN "#=" RE_SPACES RE_VAR RE_END
|
||||||
|
RE_BINARY = 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_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
|
||||||
|
@ -52,6 +53,10 @@ BEGIN {
|
||||||
if (match($0, RE_ALIAS, m)) {
|
if (match($0, RE_ALIAS, m)) {
|
||||||
print m[1]
|
print m[1]
|
||||||
}
|
}
|
||||||
|
} else if (action == "binaries") {
|
||||||
|
if (match($0, RE_BINARY, m)) {
|
||||||
|
binaries[m[1]] = ""
|
||||||
|
}
|
||||||
} else if (action == "commands") {
|
} else if (action == "commands") {
|
||||||
if (match($0, RE_COMMAND, m)) {
|
if (match($0, RE_COMMAND, m)) {
|
||||||
print m[1]
|
print m[1]
|
||||||
|
@ -80,6 +85,18 @@ BEGIN {
|
||||||
} else {
|
} else {
|
||||||
reset()
|
reset()
|
||||||
}
|
}
|
||||||
|
} else if (action == "commands functions") {
|
||||||
|
if (match($0, RE_COMMAND, m)) {
|
||||||
|
append(m[1])
|
||||||
|
} else if (match($0, RE_FUNCTION, m)) {
|
||||||
|
n = split(doc, array, "\n")
|
||||||
|
for (i = 1; i<= n; i++) {
|
||||||
|
print array[i] " " m[1]
|
||||||
|
}
|
||||||
|
reset()
|
||||||
|
} else {
|
||||||
|
reset()
|
||||||
|
}
|
||||||
} else if (action == "doc") {
|
} else if (action == "doc") {
|
||||||
# doc
|
# doc
|
||||||
if (match($0, RE_SHEBANG, m)) {
|
if (match($0, RE_SHEBANG, m)) {
|
||||||
|
@ -143,3 +160,11 @@ BEGIN {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
END {
|
||||||
|
if (action == "binaries") {
|
||||||
|
for (binary in binaries) {
|
||||||
|
print binary
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
51
sh/code.sh
51
sh/code.sh
|
@ -18,8 +18,12 @@ _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 binaries
|
||||||
|
_rwx_code_binaries=""
|
||||||
# cache for code commands
|
# cache for code commands
|
||||||
_rwx_code_commands=""
|
_rwx_code_commands=""
|
||||||
|
# cache for code commands functions
|
||||||
|
_rwx_code_commands_functions=""
|
||||||
# cache for code constants
|
# cache for code constants
|
||||||
_rwx_code_constants=""
|
_rwx_code_constants=""
|
||||||
# cache for code functions
|
# cache for code functions
|
||||||
|
@ -99,7 +103,7 @@ rwx_code_aliases() {
|
||||||
echo "${_rwx_code_aliases}"
|
echo "${_rwx_code_aliases}"
|
||||||
}
|
}
|
||||||
|
|
||||||
# find aliased function
|
# find alias function
|
||||||
rwx_code_alias_function() {
|
rwx_code_alias_function() {
|
||||||
local target="${1}"
|
local target="${1}"
|
||||||
local line name
|
local line name
|
||||||
|
@ -114,17 +118,43 @@ ${_rwx_code_aliases_functions}
|
||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# find command function
|
||||||
|
rwx_code_command_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_commands_functions}
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
# show the cached aliases and functions
|
# show the cached aliases and functions
|
||||||
#= rcaf
|
#= rcaf
|
||||||
rwx_code_aliases_functions() {
|
rwx_code_aliases_functions() {
|
||||||
echo "${_rwx_code_aliases_functions}"
|
echo "${_rwx_code_aliases_functions}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# show the cached binaries
|
||||||
|
rwx_code_binaries() {
|
||||||
|
echo "${_rwx_code_binaries}"
|
||||||
|
}
|
||||||
|
|
||||||
# show the cached commands
|
# show the cached commands
|
||||||
rwx_code_commands() {
|
rwx_code_commands() {
|
||||||
echo "${_rwx_code_commands}"
|
echo "${_rwx_code_commands}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# show the cached commands and functions
|
||||||
|
#= rccf
|
||||||
|
rwx_code_commands_functions() {
|
||||||
|
echo "${_rwx_code_commands_functions}"
|
||||||
|
}
|
||||||
|
|
||||||
# show the cached constants
|
# show the cached constants
|
||||||
#= rcc
|
#= rcc
|
||||||
rwx_code_constants() {
|
rwx_code_constants() {
|
||||||
|
@ -170,10 +200,8 @@ rwx_code_doc() {
|
||||||
}
|
}
|
||||||
|
|
||||||
rwx_code_load() {
|
rwx_code_load() {
|
||||||
# parse aliases
|
|
||||||
_rwx_code_aliases="$(rwx_code_parse "aliases")"
|
|
||||||
# parse aliases functions
|
|
||||||
local line text
|
local line text
|
||||||
|
# parse aliases functions
|
||||||
_rwx_code_aliases_functions="$(rwx_code_parse "aliases functions")"
|
_rwx_code_aliases_functions="$(rwx_code_parse "aliases functions")"
|
||||||
while IFS= read -r line; do
|
while IFS= read -r line; do
|
||||||
text="$(echo "${line}" | sed "s| |() { |")"
|
text="$(echo "${line}" | sed "s| |() { |")"
|
||||||
|
@ -182,6 +210,19 @@ rwx_code_load() {
|
||||||
done <<EOF
|
done <<EOF
|
||||||
${_rwx_code_aliases_functions}
|
${_rwx_code_aliases_functions}
|
||||||
EOF
|
EOF
|
||||||
|
# parse commands functions
|
||||||
|
_rwx_code_commands_functions="$(rwx_code_parse "commands functions")"
|
||||||
|
while IFS= read -r line; do
|
||||||
|
text="$(echo "${line}" | sed "s| |() { |")"
|
||||||
|
text="${text} \"\${@}\"; }"
|
||||||
|
eval "${text}"
|
||||||
|
done <<EOF
|
||||||
|
${_rwx_code_commands_functions}
|
||||||
|
EOF
|
||||||
|
# parse aliases
|
||||||
|
_rwx_code_aliases="$(rwx_code_parse "aliases")"
|
||||||
|
# parse binaries
|
||||||
|
_rwx_code_binaries="$(rwx_code_parse "binaries")"
|
||||||
# parse commands
|
# parse commands
|
||||||
_rwx_code_commands="$(rwx_code_parse "commands")"
|
_rwx_code_commands="$(rwx_code_parse "commands")"
|
||||||
# parse constants
|
# parse constants
|
||||||
|
@ -222,7 +263,7 @@ rwx_code_main() {
|
||||||
if [ -n "${command}" ]; then
|
if [ -n "${command}" ]; then
|
||||||
local function
|
local function
|
||||||
# find the matching function
|
# find the matching function
|
||||||
function="$(rwx_code_alias_function "${command}")"
|
function="$(rwx_code_command_function "${command}")"
|
||||||
if [ -n "${function}" ]; then
|
if [ -n "${function}" ]; then
|
||||||
"${function}" "${@}"
|
"${function}" "${@}"
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -22,7 +22,8 @@ rwx_test_code() {
|
||||||
"functions" \
|
"functions" \
|
||||||
"aliases" \
|
"aliases" \
|
||||||
"aliases_functions" \
|
"aliases_functions" \
|
||||||
"commands"
|
"commands" \
|
||||||
|
"commands_functions"
|
||||||
rwx_code
|
rwx_code
|
||||||
for items in "${@}"; do
|
for items in "${@}"; do
|
||||||
echo
|
echo
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue