From 23c0c1879788bb07b7ef789a1e971043c9b8c5ba Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Tue, 8 Jul 2025 17:01:10 +0200 Subject: [PATCH 01/10] =?UTF-8?q?awk/=E2=86=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sh/code.awk | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sh/code.awk b/sh/code.awk index dd4423b..b3006ee 100644 --- a/sh/code.awk +++ b/sh/code.awk @@ -20,13 +20,14 @@ function reset() { BEGIN { RE_ANY = "(.*)" + RE_BEGIN = "^" RE_CONST = "([_A-Z][_0-9A-Z]*)" RE_SET = "=.*" RE_SPACE = "[[:space:]]" - RE_SPACES = RE_SPACE "*" RE_VAR = "([_a-z][_0-9a-z]*)" - RE_BEGIN = "^" + RE_SPACES = RE_SPACE "*" + RE_END = RE_SPACES "$" RE_FUNC = RE_SPACES "\\(" RE_SPACES "\\)" RE_SPACES "{" From faeda4feb91627d8b4d3f0d5b50294a7a795daec Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Tue, 8 Jul 2025 20:37:33 +0200 Subject: [PATCH 02/10] awk/eval --- sh/code.awk | 6 +++++- sh/code.sh | 19 +------------------ 2 files changed, 6 insertions(+), 19 deletions(-) diff --git a/sh/code.awk b/sh/code.awk index b3006ee..dacbdc2 100644 --- a/sh/code.awk +++ b/sh/code.awk @@ -5,6 +5,10 @@ function append(line) { doc = doc line } +function eval(alias, target) { + print alias "() { " target " \"\\${@}\"; }" +} + function output(name, type) { print "↙ " type print name @@ -80,7 +84,7 @@ BEGIN { } else if (match($0, RE_FUNCTION, m)) { split(doc, array, "\n") for (item in array) { - print array[item] " " m[1] + eval(array[item], m[1]) } reset() } else { diff --git a/sh/code.sh b/sh/code.sh index d046dbb..3c033ea 100644 --- a/sh/code.sh +++ b/sh/code.sh @@ -103,21 +103,6 @@ rwx_code_aliases() { echo "${_rwx_code_aliases}" } -# find alias function -rwx_code_alias_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 < Date: Tue, 8 Jul 2025 20:43:24 +0200 Subject: [PATCH 03/10] fix --- sh/code.awk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sh/code.awk b/sh/code.awk index dacbdc2..26f3cfc 100644 --- a/sh/code.awk +++ b/sh/code.awk @@ -6,7 +6,7 @@ function append(line) { } function eval(alias, target) { - print alias "() { " target " \"\\${@}\"; }" + print alias "() { " target " \"${@}\"; }" } function output(name, type) { From ffdfe0fc90b4eae2c3d05452c2034412a4158540 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Tue, 8 Jul 2025 20:57:42 +0200 Subject: [PATCH 04/10] commands/eval --- sh/code.awk | 2 +- sh/code.sh | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/sh/code.awk b/sh/code.awk index 26f3cfc..7de8daf 100644 --- a/sh/code.awk +++ b/sh/code.awk @@ -96,7 +96,7 @@ BEGIN { } else if (match($0, RE_FUNCTION, m)) { split(doc, array, "\n") for (item in array) { - print array[item] " " m[1] + eval(array[item], m[1]) } reset() } else { diff --git a/sh/code.sh b/sh/code.sh index 3c033ea..29e4eec 100644 --- a/sh/code.sh +++ b/sh/code.sh @@ -196,9 +196,7 @@ EOF # parse commands functions _rwx_code_commands_functions="$(rwx_code_parse "commands functions")" while IFS= read -r line; do - text="$(echo "${line}" | sed "s| |() { |")" - text="${text} \"\${@}\"; }" - eval "${text}" + eval "${line}" done < Date: Tue, 8 Jul 2025 21:18:50 +0200 Subject: [PATCH 05/10] command function --- sh/code.awk | 15 +++++++++++++++ sh/code.sh | 18 +++++++----------- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/sh/code.awk b/sh/code.awk index 7de8daf..c757118 100644 --- a/sh/code.awk +++ b/sh/code.awk @@ -102,6 +102,21 @@ BEGIN { } else { reset() } + } else if (action == "command function") { + if (match($0, RE_COMMAND, m)) { + append(m[1]) + } else if (match($0, RE_FUNCTION, m)) { + split(doc, array, "\n") + for (item in array) { + if (item == target) { + print m[1] + exit + } + } + 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 29e4eec..5a67869 100644 --- a/sh/code.sh +++ b/sh/code.sh @@ -105,17 +105,13 @@ rwx_code_aliases() { # 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 < Date: Tue, 8 Jul 2025 21:19:41 +0200 Subject: [PATCH 06/10] task/completion --- readme.md | 1 + 1 file changed, 1 insertion(+) diff --git a/readme.md b/readme.md index e78c221..9f427d3 100644 --- a/readme.md +++ b/readme.md @@ -116,6 +116,7 @@ Two interpreted languages for flexibility. * tmux * get unresolved path for new panes & windows * source code + * bash completion * doc parsing algorithm * install commands * remove existing before From ab53ee87e186bfe97d5f3e011e2af8b9656af7b3 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Tue, 8 Jul 2025 21:21:49 +0200 Subject: [PATCH 07/10] match/alias --- sh/code.awk | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sh/code.awk b/sh/code.awk index c757118..3d1db60 100644 --- a/sh/code.awk +++ b/sh/code.awk @@ -46,7 +46,7 @@ BEGIN { RE_SHEBANG = RE_BEGIN "#!" RE_SPACES RE_ANY RE_END RE_VARIABLE = RE_BEGIN RE_VAR RE_SET RE_END - alias = 0 + match_alias = 0 command = 0 f = "" reset() @@ -130,7 +130,7 @@ BEGIN { } else if (match($0, RE_ALIAS, m)) { append("= " m[1]) if (m[1] == target) { - alias = 1 + match_alias = 1 } } else if (match($0, RE_COMMAND, m)) { append("/ " m[1]) @@ -159,7 +159,7 @@ BEGIN { } else if (match($0, RE_FUNCTION, m)) { f = m[1] } else if (match($0, RE_CLOSE, m)) { - if (alias) { + if (match_alias) { print "= " target output(f, "function") } else if (command) { From 359726e070bc66288f710787cb9a65e06a9675bb Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Tue, 8 Jul 2025 21:23:49 +0200 Subject: [PATCH 08/10] match/command --- sh/code.awk | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sh/code.awk b/sh/code.awk index 3d1db60..51afc9b 100644 --- a/sh/code.awk +++ b/sh/code.awk @@ -46,9 +46,9 @@ BEGIN { RE_SHEBANG = RE_BEGIN "#!" RE_SPACES RE_ANY RE_END RE_VARIABLE = RE_BEGIN RE_VAR RE_SET RE_END - match_alias = 0 - command = 0 f = "" + match_alias = 0 + match_command = 0 reset() module = 0 } @@ -135,7 +135,7 @@ BEGIN { } else if (match($0, RE_COMMAND, m)) { append("/ " m[1]) if (m[1] == target) { - command = 1 + match_command = 1 } # set } else if (match($0, RE_CONSTANT, m)) { @@ -162,7 +162,7 @@ BEGIN { if (match_alias) { print "= " target output(f, "function") - } else if (command) { + } else if (match_command) { print "/ " target output(f, "function") } else if (f == target) { From b62edad33c077624fe63a561f6c242ddb6e2f888 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Tue, 8 Jul 2025 21:25:44 +0200 Subject: [PATCH 09/10] match/module --- sh/code.awk | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sh/code.awk b/sh/code.awk index 51afc9b..c68e746 100644 --- a/sh/code.awk +++ b/sh/code.awk @@ -49,8 +49,8 @@ BEGIN { f = "" match_alias = 0 match_command = 0 + match_module = 0 reset() - module = 0 } { @@ -154,7 +154,7 @@ BEGIN { } else if (match($0, RE_MODULE, m)) { reset() if (m[1] == target) { - module = 1 + match_module = 1 } } else if (match($0, RE_FUNCTION, m)) { f = m[1] @@ -172,7 +172,7 @@ BEGIN { reset() } } else { - if (module) { + if (match_module) { output(target, "module") } else { reset() From 67e8f3a89c9e2b75eda3f9c104fe264020dcc8df Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Tue, 8 Jul 2025 21:35:30 +0200 Subject: [PATCH 10/10] fix --- sh/code.awk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sh/code.awk b/sh/code.awk index c68e746..995174f 100644 --- a/sh/code.awk +++ b/sh/code.awk @@ -108,7 +108,7 @@ BEGIN { } else if (match($0, RE_FUNCTION, m)) { split(doc, array, "\n") for (item in array) { - if (item == target) { + if (array[item] == target) { print m[1] exit }