diff --git a/sh/code.awk b/sh/code.awk index fba6da4..b722bec 100644 --- a/sh/code.awk +++ b/sh/code.awk @@ -31,6 +31,7 @@ BEGIN { RE_FUNC = RE_SPACES "\\(" RE_SPACES "\\)" RE_SPACES "{" 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_COMMAND = RE_BEGIN "#/" RE_SPACES RE_VAR RE_END RE_CONSTANT = RE_BEGIN RE_CONST RE_SET RE_END @@ -52,6 +53,10 @@ BEGIN { if (match($0, RE_ALIAS, m)) { print m[1] } + } else if (action == "binaries") { + if (match($0, RE_BINARY, m)) { + binaries[m[1]] = "" + } } else if (action == "commands") { if (match($0, RE_COMMAND, m)) { print m[1] @@ -80,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)) { @@ -143,3 +160,11 @@ BEGIN { } } } + +END { + if (action == "binaries") { + for (binary in binaries) { + print binary + } + } +} diff --git a/sh/code.sh b/sh/code.sh index 76881b1..d046dbb 100644 --- a/sh/code.sh +++ b/sh/code.sh @@ -18,8 +18,12 @@ _rwx_code_awk="$(cat "${RWX_ROOT_SYSTEM}/code.awk")" _rwx_code_aliases="" # cache for code aliases functions _rwx_code_aliases_functions="" +# cache for code binaries +_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 @@ -99,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 @@ -114,17 +118,43 @@ ${_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 <