From 030be80a01349d94d9085aac8bc51a5586f58eb7 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Fri, 11 Jul 2025 03:03:15 +0200 Subject: [PATCH 1/8] filter/aliases --- sh/core/code.awk | 6 +++--- sh/core/code.sh | 14 +++++++++++++- 2 files changed, 16 insertions(+), 4 deletions(-) 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 From e4ac8f0ae66f5e8d3bc441375e132d329c4b3f14 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Fri, 11 Jul 2025 03:11:46 +0200 Subject: [PATCH 2/8] fix --- sh/core/code.awk | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sh/core/code.awk b/sh/core/code.awk index ae3c445..0cce4aa 100644 --- a/sh/core/code.awk +++ b/sh/core/code.awk @@ -106,7 +106,7 @@ BEGIN { print m[1] } } else if (action == "aliases functions") { - if (match($0, RE_ALIAS, m)) { + if (match($0, re["alias"], m)) { append(m[1]) } else if (match($0, RE_FUNCTION, m)) { split(doc, array, "\n") @@ -154,7 +154,7 @@ BEGIN { } else { append(m[1]) } - } else if (match($0, RE_ALIAS, m)) { + } else if (match($0, re["alias"], m)) { append("= " m[1]) if (m[1] == target) { match_alias = 1 From 65d701556a599ff6002f2a0388baf9c947b53db3 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Fri, 11 Jul 2025 03:17:22 +0200 Subject: [PATCH 3/8] filter/functions --- sh/core/code.awk | 14 +++++--------- sh/core/code.sh | 2 +- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/sh/core/code.awk b/sh/core/code.awk index 0cce4aa..3cc1b76 100644 --- a/sh/core/code.awk +++ b/sh/core/code.awk @@ -43,7 +43,7 @@ BEGIN { RE_COMMENT = RE_BEGIN "#" RE_ANY RE_END RE_CONSTANT = RE_BEGIN RE_CONST RE_SET RE_END RE_DOC = RE_BEGIN RE_SPACES "#" RE_SPACE RE_ANY RE_END - RE_FUNCTION = RE_BEGIN RE_VAR RE_FUNC RE_END + re["function"] = RE_BEGIN RE_VAR RE_FUNC RE_END RE_MODULE = RE_BEGIN "#\\." RE_SPACES RE_ANY RE_END RE_SHEBANG = RE_BEGIN "#!" RE_SPACES RE_ANY RE_END RE_TASK = RE_BEGIN RE_SPACES "#" RE_SPACES RE_TSK RE_ANY RE_END @@ -74,10 +74,6 @@ BEGIN { if (match($0, RE_CONSTANT, m)) { print m[1] } - } else if (action == "functions") { - if (match($0, RE_FUNCTION, m)) { - print m[1] - } } else if (action == "tasks") { if (match($0, RE_MODULE, m)) { if (output_tasks) { @@ -108,7 +104,7 @@ BEGIN { } else if (action == "aliases functions") { if (match($0, re["alias"], m)) { append(m[1]) - } else if (match($0, RE_FUNCTION, m)) { + } else if (match($0, re["function"], m)) { split(doc, array, "\n") for (item in array) { eval(array[item], m[1]) @@ -120,7 +116,7 @@ BEGIN { } else if (action == "commands functions") { if (match($0, RE_COMMAND, m)) { append(m[1]) - } else if (match($0, RE_FUNCTION, m)) { + } else if (match($0, re["function"], m)) { split(doc, array, "\n") for (item in array) { eval(array[item], m[1]) @@ -132,7 +128,7 @@ BEGIN { } else if (action == "command function") { if (match($0, RE_COMMAND, m)) { append(m[1]) - } else if (match($0, RE_FUNCTION, m)) { + } else if (match($0, re["function"], m)) { split(doc, array, "\n") for (item in array) { if (array[item] == target) { @@ -183,7 +179,7 @@ BEGIN { if (m[1] == target) { match_module = 1 } - } else if (match($0, RE_FUNCTION, m)) { + } else if (match($0, re["function"], m)) { f = m[1] } else if (match($0, RE_CLOSE, m)) { if (match_alias) { diff --git a/sh/core/code.sh b/sh/core/code.sh index 90f818c..b21720c 100644 --- a/sh/core/code.sh +++ b/sh/core/code.sh @@ -252,7 +252,7 @@ EOF # parse constants _rwx_code_constants="$(rwx_code_parse "constants")" # parse functions - _rwx_code_functions="$(rwx_code_parse "functions")" + _rwx_code_functions="$(rwx_code_action_target "filter" "function")" # parse tasks _rwx_code_tasks="$(rwx_code_parse "tasks")" # parse variables From 705e86f18b90d91c2fa5f8f5ce06e66a5961eafd Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Fri, 11 Jul 2025 03:31:24 +0200 Subject: [PATCH 4/8] filter/variables --- sh/core/code.awk | 6 +++--- sh/core/code.sh | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/sh/core/code.awk b/sh/core/code.awk index 3cc1b76..9744d9c 100644 --- a/sh/core/code.awk +++ b/sh/core/code.awk @@ -47,7 +47,7 @@ BEGIN { RE_MODULE = RE_BEGIN "#\\." RE_SPACES RE_ANY RE_END RE_SHEBANG = RE_BEGIN "#!" RE_SPACES RE_ANY RE_END RE_TASK = RE_BEGIN RE_SPACES "#" RE_SPACES RE_TSK RE_ANY RE_END - RE_VARIABLE = RE_BEGIN RE_VAR RE_SET RE_END + re["variable"] = RE_BEGIN RE_VAR RE_SET RE_END f = "" match_alias = 0 @@ -98,7 +98,7 @@ BEGIN { match_task = 0 } } else if (action == "variables") { - if (match($0, RE_VARIABLE, m)) { + if (match($0, re["variable"], m)) { print m[1] } } else if (action == "aliases functions") { @@ -167,7 +167,7 @@ BEGIN { } else { reset() } - } else if (match($0, RE_VARIABLE, m)) { + } else if (match($0, re["variable"], m)) { if (m[1] == target) { output(m[1], "variable") } else { diff --git a/sh/core/code.sh b/sh/core/code.sh index b21720c..a87b213 100644 --- a/sh/core/code.sh +++ b/sh/core/code.sh @@ -256,7 +256,7 @@ EOF # parse tasks _rwx_code_tasks="$(rwx_code_parse "tasks")" # parse variables - _rwx_code_variables="$(rwx_code_parse "variables")" + _rwx_code_variables="$(rwx_code_action_target "filter" "variable")" } rwx_code_parse() { From c9c35169be10ac53f1788c67eac6631b1fac72cd Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Fri, 11 Jul 2025 13:58:53 +0200 Subject: [PATCH 5/8] tasks --- sh/core/code.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sh/core/code.sh b/sh/core/code.sh index a87b213..0dce975 100644 --- a/sh/core/code.sh +++ b/sh/core/code.sh @@ -254,7 +254,7 @@ EOF # parse functions _rwx_code_functions="$(rwx_code_action_target "filter" "function")" # parse tasks - _rwx_code_tasks="$(rwx_code_parse "tasks")" + _rwx_code_tasks="$(rwx_code_action_target "tasks")" # parse variables _rwx_code_variables="$(rwx_code_action_target "filter" "variable")" } From b9c14b7dd8da147bda70636e8fea560189e2f9a3 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Fri, 11 Jul 2025 14:03:25 +0200 Subject: [PATCH 6/8] filter/constants --- sh/core/code.awk | 8 ++------ sh/core/code.sh | 2 +- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/sh/core/code.awk b/sh/core/code.awk index 9744d9c..aa9ad51 100644 --- a/sh/core/code.awk +++ b/sh/core/code.awk @@ -41,7 +41,7 @@ BEGIN { RE_CLOSE = RE_BEGIN "}" RE_SPACES RE_END RE_COMMAND = RE_BEGIN "#/" RE_SPACES RE_VAR RE_END RE_COMMENT = RE_BEGIN "#" RE_ANY RE_END - RE_CONSTANT = RE_BEGIN RE_CONST RE_SET RE_END + re["constant"] = RE_BEGIN RE_CONST RE_SET RE_END RE_DOC = RE_BEGIN RE_SPACES "#" RE_SPACE RE_ANY RE_END re["function"] = RE_BEGIN RE_VAR RE_FUNC RE_END RE_MODULE = RE_BEGIN "#\\." RE_SPACES RE_ANY RE_END @@ -70,10 +70,6 @@ BEGIN { if (match($0, RE_COMMAND, m)) { print m[1] } - } else if (action == "constants") { - if (match($0, RE_CONSTANT, m)) { - print m[1] - } } else if (action == "tasks") { if (match($0, RE_MODULE, m)) { if (output_tasks) { @@ -161,7 +157,7 @@ BEGIN { match_command = 1 } # set - } else if (match($0, RE_CONSTANT, m)) { + } else if (match($0, re["constant"], m)) { if (m[1] == target) { output(m[1], "constant") } else { diff --git a/sh/core/code.sh b/sh/core/code.sh index 0dce975..ed3e21b 100644 --- a/sh/core/code.sh +++ b/sh/core/code.sh @@ -250,7 +250,7 @@ EOF # parse commands _rwx_code_commands="$(rwx_code_parse "commands")" # parse constants - _rwx_code_constants="$(rwx_code_parse "constants")" + _rwx_code_constants="$(rwx_code_action_target "filter" "constants")" # parse functions _rwx_code_functions="$(rwx_code_action_target "filter" "function")" # parse tasks From 8d8042fefe9b188fa8c4510b61469125b2a12f49 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Fri, 11 Jul 2025 15:49:23 +0200 Subject: [PATCH 7/8] tasks/fixme,todo --- sh/core/code.awk | 8 +++++++- sh/core/code.sh | 16 ++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/sh/core/code.awk b/sh/core/code.awk index aa9ad51..78aa6b7 100644 --- a/sh/core/code.awk +++ b/sh/core/code.awk @@ -82,7 +82,13 @@ BEGIN { match_task = 0 output_module = ". " m[1] } else if (match($0, RE_TASK, m)) { - match_task = 1 + if (target) { + if (target == m[1]) { + match_task = 1 + } + } else { + match_task = 1 + } append($0) } else if (match($0, RE_COMMENT, m)) { append($0) diff --git a/sh/core/code.sh b/sh/core/code.sh index ed3e21b..4c12e49 100644 --- a/sh/core/code.sh +++ b/sh/core/code.sh @@ -36,6 +36,8 @@ _rwx_code_constants="" _rwx_code_functions="" # cache for code tasks _rwx_code_tasks="" +_rwx_code_tasks_fixme="" +_rwx_code_tasks_todo="" # cache for code variables _rwx_code_variables="" @@ -195,6 +197,18 @@ rwx_code_tasks() { echo "${_rwx_code_tasks}" } +# show the cached fixme tasks +#= rctf +rwx_code_tasks_fixme() { + echo "${_rwx_code_tasks_fixme}" +} + +# show the cached todo tasks +#= rctt +rwx_code_tasks_todo() { + echo "${_rwx_code_tasks_todo}" +} + # show the cached variables #= rcv rwx_code_variables() { @@ -255,6 +269,8 @@ EOF _rwx_code_functions="$(rwx_code_action_target "filter" "function")" # parse tasks _rwx_code_tasks="$(rwx_code_action_target "tasks")" + _rwx_code_tasks_fixme="$(rwx_code_action_target "tasks" "FIXME")" + _rwx_code_tasks_todo="$(rwx_code_action_target "tasks" "TODO")" # parse variables _rwx_code_variables="$(rwx_code_action_target "filter" "variable")" } From f9252e1ee8661e6b6994231ae08356651c01c5ee Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Fri, 11 Jul 2025 15:52:38 +0200 Subject: [PATCH 8/8] alias/function,variable --- sh/core/code.awk | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/sh/core/code.awk b/sh/core/code.awk index 78aa6b7..bfdd362 100644 --- a/sh/core/code.awk +++ b/sh/core/code.awk @@ -5,10 +5,14 @@ function append(line) { doc = doc line } -function eval(alias, target) { +function alias_function(alias, target) { print alias "() { " target " \"${@}\"; }" } +function alias_variable(alias, target) { + print alias "() { echo \"${" target "}\"; }" +} + function output(name, type) { print "↙ " type print name @@ -109,7 +113,7 @@ BEGIN { } else if (match($0, re["function"], m)) { split(doc, array, "\n") for (item in array) { - eval(array[item], m[1]) + alias_function(array[item], m[1]) } reset() } else { @@ -121,7 +125,7 @@ BEGIN { } else if (match($0, re["function"], m)) { split(doc, array, "\n") for (item in array) { - eval(array[item], m[1]) + alias_function(array[item], m[1]) } reset() } else {