diff --git a/sh/core/code.awk b/sh/core/code.awk index e9599cb..ae3c445 100644 --- a/sh/core/code.awk +++ b/sh/core/code.awk @@ -36,7 +36,7 @@ BEGIN { RE_END = 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_COMMAND = RE_BEGIN "#/" RE_SPACES RE_VAR RE_END @@ -58,8 +58,8 @@ BEGIN { } { - if (action == "aliases") { - if (match($0, RE_ALIAS, m)) { + if (action == "filter") { + if (match($0, re[target], m)) { print m[1] } } else if (action == "binaries") { diff --git a/sh/core/code.sh b/sh/core/code.sh index 91cf559..90f818c 100644 --- a/sh/core/code.sh +++ b/sh/core/code.sh @@ -107,6 +107,18 @@ rwx_code_awk() { echo "${_rwx_code_awk}" } +# call awk for action with target +rwx_code_action_target() { + local action="${1}" + local target="${2}" + [ -n "${action}" ] || return + rwx_code_cache | + awk \ + -v action="${action}" \ + -v target="${target}" \ + "${_rwx_code_awk}" +} + # show the cached aliases #= rca rwx_code_aliases() { @@ -232,7 +244,7 @@ EOF ${_rwx_code_commands_functions} EOF # parse aliases - _rwx_code_aliases="$(rwx_code_parse "aliases")" + _rwx_code_aliases="$(rwx_code_action_target "filter" "alias")" # parse binaries _rwx_code_binaries="$(rwx_code_parse "binaries")" # parse commands