From 9b61976835711b62e238577f644336a191b6eb47 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Tue, 8 Jul 2025 15:48:13 +0200 Subject: [PATCH] commands/functions --- sh/code.awk | 12 ++++++++++++ sh/code.sh | 25 ++++++++++++++++++++++++- sh/test.sh | 3 ++- 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/sh/code.awk b/sh/code.awk index 4ef8e69..b722bec 100644 --- a/sh/code.awk +++ b/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)) { diff --git a/sh/code.sh b/sh/code.sh index f0f5474..8689552 100644 --- a/sh/code.sh +++ b/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 <