Compare commits
6 commits
d80b61f490
...
b62edad33c
Author | SHA1 | Date | |
---|---|---|---|
b62edad33c | |||
359726e070 | |||
ab53ee87e1 | |||
94eb3d2585 | |||
278dd75556 | |||
ffdfe0fc90 |
3 changed files with 34 additions and 24 deletions
|
@ -116,6 +116,7 @@ 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
|
||||||
|
|
35
sh/code.awk
35
sh/code.awk
|
@ -46,11 +46,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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -96,7 +96,22 @@ 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) {
|
||||||
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 (item == target) {
|
||||||
|
print m[1]
|
||||||
|
exit
|
||||||
|
}
|
||||||
}
|
}
|
||||||
reset()
|
reset()
|
||||||
} else {
|
} else {
|
||||||
|
@ -115,12 +130,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) {
|
||||||
alias = 1
|
match_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) {
|
||||||
command = 1
|
match_command = 1
|
||||||
}
|
}
|
||||||
# set
|
# set
|
||||||
} else if (match($0, RE_CONSTANT, m)) {
|
} else if (match($0, RE_CONSTANT, m)) {
|
||||||
|
@ -139,15 +154,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) {
|
||||||
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 (alias) {
|
if (match_alias) {
|
||||||
print "= " target
|
print "= " target
|
||||||
output(f, "function")
|
output(f, "function")
|
||||||
} else if (command) {
|
} else if (match_command) {
|
||||||
print "/ " target
|
print "/ " target
|
||||||
output(f, "function")
|
output(f, "function")
|
||||||
} else if (f == target) {
|
} else if (f == target) {
|
||||||
|
@ -157,7 +172,7 @@ BEGIN {
|
||||||
reset()
|
reset()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (module) {
|
if (match_module) {
|
||||||
output(target, "module")
|
output(target, "module")
|
||||||
} else {
|
} else {
|
||||||
reset()
|
reset()
|
||||||
|
|
22
sh/code.sh
22
sh/code.sh
|
@ -105,17 +105,13 @@ rwx_code_aliases() {
|
||||||
|
|
||||||
# find command function
|
# find command function
|
||||||
rwx_code_command_function() {
|
rwx_code_command_function() {
|
||||||
local target="${1}"
|
local name="${1}"
|
||||||
local line name
|
[ -n "${name}" ] || return
|
||||||
while IFS= read -r line; do
|
rwx_code |
|
||||||
name="$(echo "${line}" | awk "{print \$1}")"
|
awk \
|
||||||
if [ "${name}" = "${target}" ]; then
|
--assign action="command function" \
|
||||||
echo "${line}" |
|
--assign target="${name}" \
|
||||||
awk "{print \$2}"
|
"${_rwx_code_awk}"
|
||||||
fi
|
|
||||||
done <<EOF
|
|
||||||
${_rwx_code_commands_functions}
|
|
||||||
EOF
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# show the cached aliases and functions
|
# show the cached aliases and functions
|
||||||
|
@ -196,9 +192,7 @@ 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
|
||||||
text="$(echo "${line}" | sed "s| |() { |")"
|
eval "${line}"
|
||||||
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