Compare commits
2 commits
0926d058f5
...
3b222fda83
Author | SHA1 | Date | |
---|---|---|---|
3b222fda83 | |||
9b61976835 |
3 changed files with 39 additions and 3 deletions
12
sh/code.awk
12
sh/code.awk
|
@ -85,6 +85,18 @@ BEGIN {
|
|||
} else {
|
||||
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") {
|
||||
# doc
|
||||
if (match($0, RE_SHEBANG, m)) {
|
||||
|
|
27
sh/code.sh
27
sh/code.sh
|
@ -22,6 +22,8 @@ _rwx_code_aliases_functions=""
|
|||
_rwx_code_binaries=""
|
||||
# cache for code commands
|
||||
_rwx_code_commands=""
|
||||
# cache for code commands functions
|
||||
_rwx_code_commands_functions=""
|
||||
# cache for code constants
|
||||
_rwx_code_constants=""
|
||||
# cache for code functions
|
||||
|
@ -101,7 +103,7 @@ rwx_code_aliases() {
|
|||
echo "${_rwx_code_aliases}"
|
||||
}
|
||||
|
||||
# find aliased function
|
||||
# find alias function
|
||||
rwx_code_alias_function() {
|
||||
local target="${1}"
|
||||
local line name
|
||||
|
@ -116,6 +118,21 @@ ${_rwx_code_aliases_functions}
|
|||
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
|
||||
#= rcaf
|
||||
rwx_code_aliases_functions() {
|
||||
|
@ -132,6 +149,12 @@ 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
|
||||
#= rcc
|
||||
rwx_code_constants() {
|
||||
|
@ -231,7 +254,7 @@ rwx_code_main() {
|
|||
if [ -n "${command}" ]; then
|
||||
local function
|
||||
# find the matching function
|
||||
function="$(rwx_code_alias_function "${command}")"
|
||||
function="$(rwx_code_command_function "${command}")"
|
||||
if [ -n "${function}" ]; then
|
||||
"${function}" "${@}"
|
||||
fi
|
||||
|
|
|
@ -22,7 +22,8 @@ rwx_test_code() {
|
|||
"functions" \
|
||||
"aliases" \
|
||||
"aliases_functions" \
|
||||
"commands"
|
||||
"commands" \
|
||||
"commands_functions"
|
||||
rwx_code
|
||||
for items in "${@}"; do
|
||||
echo
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue