Compare commits

...

8 commits

Author SHA1 Message Date
f9252e1ee8
alias/function,variable
All checks were successful
/ job (push) Successful in 2m56s
2025-07-11 15:52:38 +02:00
8d8042fefe
tasks/fixme,todo 2025-07-11 15:49:23 +02:00
b9c14b7dd8
filter/constants 2025-07-11 14:03:25 +02:00
c9c35169be
tasks 2025-07-11 13:58:53 +02:00
705e86f18b
filter/variables 2025-07-11 03:31:24 +02:00
65d701556a
filter/functions 2025-07-11 03:17:22 +02:00
e4ac8f0ae6
fix 2025-07-11 03:11:46 +02:00
030be80a01
filter/aliases 2025-07-11 03:03:15 +02:00
2 changed files with 62 additions and 32 deletions

View file

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

View file

@ -36,6 +36,8 @@ _rwx_code_constants=""
_rwx_code_functions="" _rwx_code_functions=""
# cache for code tasks # cache for code tasks
_rwx_code_tasks="" _rwx_code_tasks=""
_rwx_code_tasks_fixme=""
_rwx_code_tasks_todo=""
# cache for code variables # cache for code variables
_rwx_code_variables="" _rwx_code_variables=""
@ -107,6 +109,18 @@ rwx_code_awk() {
echo "${_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 # show the cached aliases
#= rca #= rca
rwx_code_aliases() { rwx_code_aliases() {
@ -183,6 +197,18 @@ rwx_code_tasks() {
echo "${_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 # show the cached variables
#= rcv #= rcv
rwx_code_variables() { rwx_code_variables() {
@ -232,19 +258,21 @@ EOF
${_rwx_code_commands_functions} ${_rwx_code_commands_functions}
EOF EOF
# parse aliases # parse aliases
_rwx_code_aliases="$(rwx_code_parse "aliases")" _rwx_code_aliases="$(rwx_code_action_target "filter" "alias")"
# parse binaries # parse binaries
_rwx_code_binaries="$(rwx_code_parse "binaries")" _rwx_code_binaries="$(rwx_code_parse "binaries")"
# parse commands # parse commands
_rwx_code_commands="$(rwx_code_parse "commands")" _rwx_code_commands="$(rwx_code_parse "commands")"
# parse constants # parse constants
_rwx_code_constants="$(rwx_code_parse "constants")" _rwx_code_constants="$(rwx_code_action_target "filter" "constants")"
# parse functions # parse functions
_rwx_code_functions="$(rwx_code_parse "functions")" _rwx_code_functions="$(rwx_code_action_target "filter" "function")"
# parse tasks # parse tasks
_rwx_code_tasks="$(rwx_code_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 # parse variables
_rwx_code_variables="$(rwx_code_parse "variables")" _rwx_code_variables="$(rwx_code_action_target "filter" "variable")"
} }
rwx_code_parse() { rwx_code_parse() {