awk/eval
This commit is contained in:
parent
23c0c18797
commit
faeda4feb9
2 changed files with 6 additions and 19 deletions
|
@ -5,6 +5,10 @@ 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
|
||||||
|
@ -80,7 +84,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) {
|
||||||
print array[item] " " m[1]
|
eval(array[item], m[1])
|
||||||
}
|
}
|
||||||
reset()
|
reset()
|
||||||
} else {
|
} else {
|
||||||
|
|
19
sh/code.sh
19
sh/code.sh
|
@ -103,21 +103,6 @@ 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 target="${1}"
|
local target="${1}"
|
||||||
|
@ -204,9 +189,7 @@ 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
|
||||||
text="$(echo "${line}" | sed "s| |() { |")"
|
eval "${line}"
|
||||||
text="${text} \"\${@}\"; }"
|
|
||||||
eval "${text}"
|
|
||||||
done <<EOF
|
done <<EOF
|
||||||
${_rwx_code_aliases_functions}
|
${_rwx_code_aliases_functions}
|
||||||
EOF
|
EOF
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue