diff --git a/readme.md b/readme.md index 9f427d3..e78c221 100644 --- a/readme.md +++ b/readme.md @@ -116,7 +116,6 @@ 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 diff --git a/sh/code.awk b/sh/code.awk index 995174f..dd4423b 100644 --- a/sh/code.awk +++ b/sh/code.awk @@ -5,10 +5,6 @@ function append(line) { doc = doc line } -function eval(alias, target) { - print alias "() { " target " \"${@}\"; }" -} - function output(name, type) { print "↙ " type print name @@ -24,14 +20,13 @@ 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_SPACES = RE_SPACE "*" - + RE_BEGIN = "^" RE_END = RE_SPACES "$" RE_FUNC = RE_SPACES "\\(" RE_SPACES "\\)" RE_SPACES "{" @@ -46,11 +41,11 @@ BEGIN { RE_SHEBANG = RE_BEGIN "#!" RE_SPACES RE_ANY RE_END RE_VARIABLE = RE_BEGIN RE_VAR RE_SET RE_END + alias = 0 + command = 0 f = "" - match_alias = 0 - match_command = 0 - match_module = 0 reset() + module = 0 } { @@ -84,7 +79,7 @@ BEGIN { } else if (match($0, RE_FUNCTION, m)) { split(doc, array, "\n") for (item in array) { - eval(array[item], m[1]) + print array[item] " " m[1] } reset() } else { @@ -96,22 +91,7 @@ BEGIN { } else if (match($0, RE_FUNCTION, m)) { split(doc, array, "\n") for (item in array) { - eval(array[item], m[1]) - } - reset() - } 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 (array[item] == target) { - print m[1] - exit - } + print array[item] " " m[1] } reset() } else { @@ -130,12 +110,12 @@ BEGIN { } else if (match($0, RE_ALIAS, m)) { append("= " m[1]) if (m[1] == target) { - match_alias = 1 + alias = 1 } } else if (match($0, RE_COMMAND, m)) { append("/ " m[1]) if (m[1] == target) { - match_command = 1 + command = 1 } # set } else if (match($0, RE_CONSTANT, m)) { @@ -154,15 +134,15 @@ BEGIN { } else if (match($0, RE_MODULE, m)) { reset() if (m[1] == target) { - match_module = 1 + module = 1 } } else if (match($0, RE_FUNCTION, m)) { f = m[1] } else if (match($0, RE_CLOSE, m)) { - if (match_alias) { + if (alias) { print "= " target output(f, "function") - } else if (match_command) { + } else if (command) { print "/ " target output(f, "function") } else if (f == target) { @@ -172,7 +152,7 @@ BEGIN { reset() } } else { - if (match_module) { + if (module) { output(target, "module") } else { reset() diff --git a/sh/code.sh b/sh/code.sh index 5a67869..d046dbb 100644 --- a/sh/code.sh +++ b/sh/code.sh @@ -103,15 +103,34 @@ 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 <