Compare commits
10 commits
d366245c2d
...
67e8f3a89c
Author | SHA1 | Date | |
---|---|---|---|
67e8f3a89c | |||
b62edad33c | |||
359726e070 | |||
ab53ee87e1 | |||
94eb3d2585 | |||
278dd75556 | |||
ffdfe0fc90 | |||
d80b61f490 | |||
faeda4feb9 | |||
23c0c18797 |
3 changed files with 43 additions and 45 deletions
|
@ -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
|
||||
|
|
46
sh/code.awk
46
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
|
||||
|
@ -20,13 +24,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 "{"
|
||||
|
||||
|
@ -41,11 +46,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
|
||||
}
|
||||
|
||||
{
|
||||
|
@ -79,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 {
|
||||
|
@ -91,7 +96,22 @@ 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 {
|
||||
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
|
||||
}
|
||||
}
|
||||
reset()
|
||||
} else {
|
||||
|
@ -110,12 +130,12 @@ 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])
|
||||
if (m[1] == target) {
|
||||
command = 1
|
||||
match_command = 1
|
||||
}
|
||||
# set
|
||||
} else if (match($0, RE_CONSTANT, m)) {
|
||||
|
@ -134,15 +154,15 @@ 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]
|
||||
} else if (match($0, RE_CLOSE, m)) {
|
||||
if (alias) {
|
||||
if (match_alias) {
|
||||
print "= " target
|
||||
output(f, "function")
|
||||
} else if (command) {
|
||||
} else if (match_command) {
|
||||
print "/ " target
|
||||
output(f, "function")
|
||||
} else if (f == target) {
|
||||
|
@ -152,7 +172,7 @@ BEGIN {
|
|||
reset()
|
||||
}
|
||||
} else {
|
||||
if (module) {
|
||||
if (match_module) {
|
||||
output(target, "module")
|
||||
} else {
|
||||
reset()
|
||||
|
|
41
sh/code.sh
41
sh/code.sh
|
@ -103,34 +103,15 @@ 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 <<EOF
|
||||
${_rwx_code_aliases_functions}
|
||||
EOF
|
||||
}
|
||||
|
||||
# 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 <<EOF
|
||||
${_rwx_code_commands_functions}
|
||||
EOF
|
||||
local name="${1}"
|
||||
[ -n "${name}" ] || return
|
||||
rwx_code |
|
||||
awk \
|
||||
--assign action="command function" \
|
||||
--assign target="${name}" \
|
||||
"${_rwx_code_awk}"
|
||||
}
|
||||
|
||||
# show the cached aliases and functions
|
||||
|
@ -204,18 +185,14 @@ rwx_code_load() {
|
|||
# parse aliases functions
|
||||
_rwx_code_aliases_functions="$(rwx_code_parse "aliases functions")"
|
||||
while IFS= read -r line; do
|
||||
text="$(echo "${line}" | sed "s| |() { |")"
|
||||
text="${text} \"\${@}\"; }"
|
||||
eval "${text}"
|
||||
eval "${line}"
|
||||
done <<EOF
|
||||
${_rwx_code_aliases_functions}
|
||||
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 <<EOF
|
||||
${_rwx_code_commands_functions}
|
||||
EOF
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue