From 601eef23264fc47818a13756484b650dd7ef3e59 Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Sun, 13 Jul 2025 20:43:18 +0200 Subject: [PATCH] mawk/eval --- sh/core/code.awk | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/sh/core/code.awk b/sh/core/code.awk index 6565d02..5b9ddac 100644 --- a/sh/core/code.awk +++ b/sh/core/code.awk @@ -1,9 +1,11 @@ -function alias_function(alias, name) { - print alias "() { " name " \"${@}\"; }" -} - -function alias_variable(alias, name) { - print alias "() { echo \"${" name "}\"; }" +function alias_eval(alias, name, type) { + text = alias "() { " + if (type == "function") { + text = text name " \"${@}\"" + } else if (type == "variable") { + text = text "echo \"${" name "}\"" + } + print text "; }" } function append(line) { @@ -127,7 +129,7 @@ BEGIN { } else if (match($0, re["function"], m)) { split(doc, array, "\n") for (item in array) { - alias_function(array[item], m[1]) + alias_eval(array[item], m[1], "function") } reset() } else { @@ -139,7 +141,7 @@ BEGIN { } else if (match($0, re["function"], m)) { split(doc, array, "\n") for (item in array) { - alias_function(array[item], m[1]) + alias_eval(array[item], m[1], "function") } reset() } else {