Compare commits

..

No commits in common. "f9252e1ee8661e6b6994231ae08356651c01c5ee" and "fa9a2435a4911d14e5b42502175af737854996cd" have entirely different histories.

2 changed files with 32 additions and 62 deletions

View file

@ -5,14 +5,10 @@ function append(line) {
doc = doc line
}
function alias_function(alias, target) {
function eval(alias, target) {
print alias "() { " target " \"${@}\"; }"
}
function alias_variable(alias, target) {
print alias "() { echo \"${" target "}\"; }"
}
function output(name, type) {
print "↙ " type
print name
@ -40,18 +36,18 @@ 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
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_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
re["variable"] = RE_BEGIN RE_VAR RE_SET RE_END
RE_VARIABLE = RE_BEGIN RE_VAR RE_SET RE_END
f = ""
match_alias = 0
@ -62,8 +58,8 @@ BEGIN {
}
{
if (action == "filter") {
if (match($0, re[target], m)) {
if (action == "aliases") {
if (match($0, RE_ALIAS, m)) {
print m[1]
}
} else if (action == "binaries") {
@ -74,6 +70,14 @@ 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 == "functions") {
if (match($0, RE_FUNCTION, m)) {
print m[1]
}
} else if (action == "tasks") {
if (match($0, RE_MODULE, m)) {
if (output_tasks) {
@ -86,13 +90,7 @@ BEGIN {
match_task = 0
output_module = ". " m[1]
} else if (match($0, RE_TASK, m)) {
if (target) {
if (target == m[1]) {
match_task = 1
}
} else {
match_task = 1
}
match_task = 1
append($0)
} else if (match($0, RE_COMMENT, m)) {
append($0)
@ -104,16 +102,16 @@ 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") {
if (match($0, re["alias"], m)) {
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) {
alias_function(array[item], m[1])
eval(array[item], m[1])
}
reset()
} else {
@ -122,10 +120,10 @@ 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) {
alias_function(array[item], m[1])
eval(array[item], m[1])
}
reset()
} else {
@ -134,7 +132,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) {
@ -156,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
@ -167,13 +165,13 @@ 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 {
reset()
}
} else if (match($0, re["variable"], m)) {
} else if (match($0, RE_VARIABLE, m)) {
if (m[1] == target) {
output(m[1], "variable")
} else {
@ -185,7 +183,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) {

View file

@ -36,8 +36,6 @@ _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=""
@ -109,18 +107,6 @@ 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() {
@ -197,18 +183,6 @@ 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() {
@ -258,21 +232,19 @@ EOF
${_rwx_code_commands_functions}
EOF
# parse aliases
_rwx_code_aliases="$(rwx_code_action_target "filter" "alias")"
_rwx_code_aliases="$(rwx_code_parse "aliases")"
# parse binaries
_rwx_code_binaries="$(rwx_code_parse "binaries")"
# parse commands
_rwx_code_commands="$(rwx_code_parse "commands")"
# parse constants
_rwx_code_constants="$(rwx_code_action_target "filter" "constants")"
_rwx_code_constants="$(rwx_code_parse "constants")"
# parse functions
_rwx_code_functions="$(rwx_code_action_target "filter" "function")"
_rwx_code_functions="$(rwx_code_parse "functions")"
# 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")"
_rwx_code_tasks="$(rwx_code_parse "tasks")"
# parse variables
_rwx_code_variables="$(rwx_code_action_target "filter" "variable")"
_rwx_code_variables="$(rwx_code_parse "variables")"
}
rwx_code_parse() {