Compare commits
No commits in common. "67e8f3a89c9e2b75eda3f9c104fe264020dcc8df" and "d366245c2df0ffc0d3d0351017950424da24141a" have entirely different histories.
67e8f3a89c
...
d366245c2d
3 changed files with 45 additions and 43 deletions
|
@ -116,7 +116,6 @@ Two interpreted languages for flexibility.
|
||||||
* tmux
|
* tmux
|
||||||
* get unresolved path for new panes & windows
|
* get unresolved path for new panes & windows
|
||||||
* source code
|
* source code
|
||||||
* bash completion
|
|
||||||
* doc parsing algorithm
|
* doc parsing algorithm
|
||||||
* install commands
|
* install commands
|
||||||
* remove existing before
|
* remove existing before
|
||||||
|
|
46
sh/code.awk
46
sh/code.awk
|
@ -5,10 +5,6 @@ function append(line) {
|
||||||
doc = doc line
|
doc = doc line
|
||||||
}
|
}
|
||||||
|
|
||||||
function eval(alias, target) {
|
|
||||||
print alias "() { " target " \"${@}\"; }"
|
|
||||||
}
|
|
||||||
|
|
||||||
function output(name, type) {
|
function output(name, type) {
|
||||||
print "↙ " type
|
print "↙ " type
|
||||||
print name
|
print name
|
||||||
|
@ -24,14 +20,13 @@ function reset() {
|
||||||
|
|
||||||
BEGIN {
|
BEGIN {
|
||||||
RE_ANY = "(.*)"
|
RE_ANY = "(.*)"
|
||||||
RE_BEGIN = "^"
|
|
||||||
RE_CONST = "([_A-Z][_0-9A-Z]*)"
|
RE_CONST = "([_A-Z][_0-9A-Z]*)"
|
||||||
RE_SET = "=.*"
|
RE_SET = "=.*"
|
||||||
RE_SPACE = "[[:space:]]"
|
RE_SPACE = "[[:space:]]"
|
||||||
|
RE_SPACES = RE_SPACE "*"
|
||||||
RE_VAR = "([_a-z][_0-9a-z]*)"
|
RE_VAR = "([_a-z][_0-9a-z]*)"
|
||||||
|
|
||||||
RE_SPACES = RE_SPACE "*"
|
RE_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 "{"
|
||||||
|
|
||||||
|
@ -46,11 +41,11 @@ BEGIN {
|
||||||
RE_SHEBANG = RE_BEGIN "#!" RE_SPACES RE_ANY RE_END
|
RE_SHEBANG = RE_BEGIN "#!" RE_SPACES RE_ANY RE_END
|
||||||
RE_VARIABLE = RE_BEGIN RE_VAR RE_SET RE_END
|
RE_VARIABLE = RE_BEGIN RE_VAR RE_SET RE_END
|
||||||
|
|
||||||
|
alias = 0
|
||||||
|
command = 0
|
||||||
f = ""
|
f = ""
|
||||||
match_alias = 0
|
|
||||||
match_command = 0
|
|
||||||
match_module = 0
|
|
||||||
reset()
|
reset()
|
||||||
|
module = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -84,7 +79,7 @@ BEGIN {
|
||||||
} 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])
|
print array[item] " " m[1]
|
||||||
}
|
}
|
||||||
reset()
|
reset()
|
||||||
} else {
|
} else {
|
||||||
|
@ -96,22 +91,7 @@ BEGIN {
|
||||||
} 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])
|
print 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()
|
reset()
|
||||||
} else {
|
} else {
|
||||||
|
@ -130,12 +110,12 @@ BEGIN {
|
||||||
} 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
|
alias = 1
|
||||||
}
|
}
|
||||||
} else if (match($0, RE_COMMAND, m)) {
|
} else if (match($0, RE_COMMAND, m)) {
|
||||||
append("/ " m[1])
|
append("/ " m[1])
|
||||||
if (m[1] == target) {
|
if (m[1] == target) {
|
||||||
match_command = 1
|
command = 1
|
||||||
}
|
}
|
||||||
# set
|
# set
|
||||||
} else if (match($0, RE_CONSTANT, m)) {
|
} else if (match($0, RE_CONSTANT, m)) {
|
||||||
|
@ -154,15 +134,15 @@ BEGIN {
|
||||||
} else if (match($0, RE_MODULE, m)) {
|
} else if (match($0, RE_MODULE, m)) {
|
||||||
reset()
|
reset()
|
||||||
if (m[1] == target) {
|
if (m[1] == target) {
|
||||||
match_module = 1
|
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 (alias) {
|
||||||
print "= " target
|
print "= " target
|
||||||
output(f, "function")
|
output(f, "function")
|
||||||
} else if (match_command) {
|
} else if (command) {
|
||||||
print "/ " target
|
print "/ " target
|
||||||
output(f, "function")
|
output(f, "function")
|
||||||
} else if (f == target) {
|
} else if (f == target) {
|
||||||
|
@ -172,7 +152,7 @@ BEGIN {
|
||||||
reset()
|
reset()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (match_module) {
|
if (module) {
|
||||||
output(target, "module")
|
output(target, "module")
|
||||||
} else {
|
} else {
|
||||||
reset()
|
reset()
|
||||||
|
|
41
sh/code.sh
41
sh/code.sh
|
@ -103,15 +103,34 @@ rwx_code_aliases() {
|
||||||
echo "${_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
|
# find command function
|
||||||
rwx_code_command_function() {
|
rwx_code_command_function() {
|
||||||
local name="${1}"
|
local target="${1}"
|
||||||
[ -n "${name}" ] || return
|
local line name
|
||||||
rwx_code |
|
while IFS= read -r line; do
|
||||||
awk \
|
name="$(echo "${line}" | awk "{print \$1}")"
|
||||||
--assign action="command function" \
|
if [ "${name}" = "${target}" ]; then
|
||||||
--assign target="${name}" \
|
echo "${line}" |
|
||||||
"${_rwx_code_awk}"
|
awk "{print \$2}"
|
||||||
|
fi
|
||||||
|
done <<EOF
|
||||||
|
${_rwx_code_commands_functions}
|
||||||
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
# show the cached aliases and functions
|
# show the cached aliases and functions
|
||||||
|
@ -185,14 +204,18 @@ rwx_code_load() {
|
||||||
# parse aliases functions
|
# parse aliases functions
|
||||||
_rwx_code_aliases_functions="$(rwx_code_parse "aliases functions")"
|
_rwx_code_aliases_functions="$(rwx_code_parse "aliases functions")"
|
||||||
while IFS= read -r line; do
|
while IFS= read -r line; do
|
||||||
eval "${line}"
|
text="$(echo "${line}" | sed "s| |() { |")"
|
||||||
|
text="${text} \"\${@}\"; }"
|
||||||
|
eval "${text}"
|
||||||
done <<EOF
|
done <<EOF
|
||||||
${_rwx_code_aliases_functions}
|
${_rwx_code_aliases_functions}
|
||||||
EOF
|
EOF
|
||||||
# parse commands functions
|
# parse commands functions
|
||||||
_rwx_code_commands_functions="$(rwx_code_parse "commands functions")"
|
_rwx_code_commands_functions="$(rwx_code_parse "commands functions")"
|
||||||
while IFS= read -r line; do
|
while IFS= read -r line; do
|
||||||
eval "${line}"
|
text="$(echo "${line}" | sed "s| |() { |")"
|
||||||
|
text="${text} \"\${@}\"; }"
|
||||||
|
eval "${text}"
|
||||||
done <<EOF
|
done <<EOF
|
||||||
${_rwx_code_commands_functions}
|
${_rwx_code_commands_functions}
|
||||||
EOF
|
EOF
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue