Compare commits
4 commits
b0afca09a5
...
1467c1158a
Author | SHA1 | Date | |
---|---|---|---|
1467c1158a | |||
30aead95e0 | |||
0ef18c113e | |||
1b077ac89a |
5 changed files with 139 additions and 91 deletions
|
@ -1,3 +1,5 @@
|
||||||
|
# large set of aliases for git commands
|
||||||
|
|
||||||
RWX_GIT_LOG_FORMAT="\
|
RWX_GIT_LOG_FORMAT="\
|
||||||
%C(auto)%h%d
|
%C(auto)%h%d
|
||||||
S %C(red)%GS
|
S %C(red)%GS
|
||||||
|
|
83
sh/doc.awk
83
sh/doc.awk
|
@ -1,83 +0,0 @@
|
||||||
function append(line) {
|
|
||||||
if (doc) {
|
|
||||||
doc = doc "\n"
|
|
||||||
}
|
|
||||||
doc = doc line
|
|
||||||
}
|
|
||||||
|
|
||||||
function output(name) {
|
|
||||||
print name
|
|
||||||
print doc
|
|
||||||
exit
|
|
||||||
}
|
|
||||||
|
|
||||||
function reset() {
|
|
||||||
doc = ""
|
|
||||||
}
|
|
||||||
|
|
||||||
BEGIN {
|
|
||||||
RE_ANY = "(.*)"
|
|
||||||
RE_NAME = "([_A-Za-z][_0-9A-Za-z]*)"
|
|
||||||
RE_SPACE = "[[:space:]]"
|
|
||||||
RE_SPACES = RE_SPACE "*"
|
|
||||||
|
|
||||||
RE_BEGIN = "^"
|
|
||||||
RE_END = RE_SPACES "$"
|
|
||||||
RE_FUNC = RE_SPACES "\\(" RE_SPACES "\\)" RE_SPACES "{"
|
|
||||||
|
|
||||||
RE_ALIAS = RE_BEGIN "#\\(" RE_SPACES RE_NAME RE_END
|
|
||||||
RE_DOC = RE_BEGIN "#" RE_SPACE RE_ANY RE_END
|
|
||||||
RE_FUNCTION = RE_BEGIN RE_NAME RE_FUNC RE_END
|
|
||||||
RE_MODULE = RE_BEGIN "#." RE_SPACES RE_NAME RE_END
|
|
||||||
RE_SET = RE_BEGIN RE_NAME "=.*" RE_END
|
|
||||||
RE_SHEBANG = RE_BEGIN "#!" RE_SPACES RE_ANY RE_END
|
|
||||||
|
|
||||||
alias = 0
|
|
||||||
reset()
|
|
||||||
module = 0
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
# doc
|
|
||||||
if (match($0, RE_SHEBANG, m)) {
|
|
||||||
append("shebang: " m[1])
|
|
||||||
} else if (match($0, RE_DOC, m)) {
|
|
||||||
append(m[1])
|
|
||||||
} else if (match($0, RE_ALIAS, m)) {
|
|
||||||
append("alias: " m[1])
|
|
||||||
if (m[1] == target) {
|
|
||||||
alias = 1
|
|
||||||
}
|
|
||||||
# not doc
|
|
||||||
} else if (match($0, RE_MODULE, m)) {
|
|
||||||
reset()
|
|
||||||
if (m[1] == target) {
|
|
||||||
module = 1
|
|
||||||
}
|
|
||||||
} else if (match($0, RE_SET, m)) {
|
|
||||||
if (m[1] == target) {
|
|
||||||
printf "set: "
|
|
||||||
output(m[1])
|
|
||||||
} else {
|
|
||||||
reset()
|
|
||||||
}
|
|
||||||
} else if (match($0, RE_FUNCTION, m)) {
|
|
||||||
if (alias) {
|
|
||||||
print "alias: " target
|
|
||||||
printf "function: "
|
|
||||||
output(m[1])
|
|
||||||
} else if (m[1] == target) {
|
|
||||||
printf "function: "
|
|
||||||
output(target)
|
|
||||||
} else {
|
|
||||||
reset()
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (module) {
|
|
||||||
printf "module: "
|
|
||||||
output(target)
|
|
||||||
} else {
|
|
||||||
reset()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
108
sh/main.awk
Normal file
108
sh/main.awk
Normal file
|
@ -0,0 +1,108 @@
|
||||||
|
function append(line) {
|
||||||
|
if (doc) {
|
||||||
|
doc = doc "\n"
|
||||||
|
}
|
||||||
|
doc = doc line
|
||||||
|
}
|
||||||
|
|
||||||
|
function output(name) {
|
||||||
|
print name
|
||||||
|
print doc
|
||||||
|
exit
|
||||||
|
}
|
||||||
|
|
||||||
|
function reset() {
|
||||||
|
doc = ""
|
||||||
|
}
|
||||||
|
|
||||||
|
BEGIN {
|
||||||
|
RE_ANY = "(.*)"
|
||||||
|
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_END = RE_SPACES "$"
|
||||||
|
RE_FUNC = RE_SPACES "\\(" RE_SPACES "\\)" RE_SPACES "{"
|
||||||
|
|
||||||
|
RE_ALIAS = RE_BEGIN "#\\(" RE_SPACES RE_VAR RE_END
|
||||||
|
RE_CONSTANT = RE_BEGIN RE_CONST RE_SET RE_END
|
||||||
|
RE_DOC = RE_BEGIN "#" RE_SPACE RE_ANY RE_END
|
||||||
|
RE_FUNCTION = RE_BEGIN RE_VAR RE_FUNC RE_END
|
||||||
|
RE_MODULE = 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
|
||||||
|
|
||||||
|
alias = 0
|
||||||
|
reset()
|
||||||
|
module = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
if (action == "alias") {
|
||||||
|
if (match($0, RE_ALIAS, m)) {
|
||||||
|
append(m[1])
|
||||||
|
} else if (match($0, RE_FUNCTION, m)) {
|
||||||
|
n = split(doc, array, "\n")
|
||||||
|
for (i = 1; i<= n; i++) {
|
||||||
|
print array[i] "() { " m[1] " \"${@}\" ; }"
|
||||||
|
}
|
||||||
|
reset()
|
||||||
|
} else {
|
||||||
|
reset()
|
||||||
|
}
|
||||||
|
} else if (action == "doc") {
|
||||||
|
# doc
|
||||||
|
if (match($0, RE_SHEBANG, m)) {
|
||||||
|
append("shebang: " m[1])
|
||||||
|
} else if (match($0, RE_DOC, m)) {
|
||||||
|
append(m[1])
|
||||||
|
} else if (match($0, RE_ALIAS, m)) {
|
||||||
|
append("alias: " m[1])
|
||||||
|
if (m[1] == target) {
|
||||||
|
alias = 1
|
||||||
|
}
|
||||||
|
# set
|
||||||
|
} else if (match($0, RE_CONSTANT, m)) {
|
||||||
|
if (m[1] == target) {
|
||||||
|
printf "constant: "
|
||||||
|
output(m[1])
|
||||||
|
} else {
|
||||||
|
reset()
|
||||||
|
}
|
||||||
|
} else if (match($0, RE_VARIABLE, m)) {
|
||||||
|
if (m[1] == target) {
|
||||||
|
printf "variable: "
|
||||||
|
output(m[1])
|
||||||
|
} else {
|
||||||
|
reset()
|
||||||
|
}
|
||||||
|
# others
|
||||||
|
} else if (match($0, RE_MODULE, m)) {
|
||||||
|
reset()
|
||||||
|
if (m[1] == target) {
|
||||||
|
module = 1
|
||||||
|
}
|
||||||
|
} else if (match($0, RE_FUNCTION, m)) {
|
||||||
|
if (alias) {
|
||||||
|
print "alias: " target
|
||||||
|
printf "function: "
|
||||||
|
output(m[1])
|
||||||
|
} else if (m[1] == target) {
|
||||||
|
printf "function: "
|
||||||
|
output(target)
|
||||||
|
} else {
|
||||||
|
reset()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (module) {
|
||||||
|
printf "module: "
|
||||||
|
output(target)
|
||||||
|
} else {
|
||||||
|
reset()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
28
sh/main.sh
28
sh/main.sh
|
@ -32,6 +32,7 @@ esac
|
||||||
RWX_ROOT_SYSTEM="/usr/local/lib/${RWX_SELF_NAME}"
|
RWX_ROOT_SYSTEM="/usr/local/lib/${RWX_SELF_NAME}"
|
||||||
RWX_SELF_USER="${HOME}/${RWX_SELF_NAME}"
|
RWX_SELF_USER="${HOME}/${RWX_SELF_NAME}"
|
||||||
|
|
||||||
|
RWX_AWK="${RWX_ROOT_SYSTEM}/${RWX_MAIN_NAME%.sh}.awk"
|
||||||
RWX_MAIN_PATH="${RWX_ROOT_SYSTEM}/${RWX_MAIN_NAME}"
|
RWX_MAIN_PATH="${RWX_ROOT_SYSTEM}/${RWX_MAIN_NAME}"
|
||||||
|
|
||||||
# ╭──────┬──────╮
|
# ╭──────┬──────╮
|
||||||
|
@ -64,6 +65,9 @@ rwx_main() {
|
||||||
# │ main │ cache │
|
# │ main │ cache │
|
||||||
# ╰──────┴───────╯
|
# ╰──────┴───────╯
|
||||||
|
|
||||||
|
# cache of all sourced code modules
|
||||||
|
_rwx_code=""
|
||||||
|
|
||||||
# cache source code of a module
|
# cache source code of a module
|
||||||
# inside a global code variable
|
# inside a global code variable
|
||||||
rwx_cache() {
|
rwx_cache() {
|
||||||
|
@ -74,7 +78,7 @@ rwx_cache() {
|
||||||
local text
|
local text
|
||||||
text="$(cat "${path}")"
|
text="$(cat "${path}")"
|
||||||
# all source code
|
# all source code
|
||||||
RWX_CODE="${RWX_CODE}\
|
_rwx_code="${_rwx_code}\
|
||||||
#. ${name}
|
#. ${name}
|
||||||
${text}
|
${text}
|
||||||
"
|
"
|
||||||
|
@ -181,17 +185,31 @@ RWX_REGEX_TARGET_FUNCTION="\
|
||||||
${RWX_REGEX_BEGIN}\\(${RWX_REGEX_FUNCTION}\\)${RWX_REGEX_OPEN}"
|
${RWX_REGEX_BEGIN}\\(${RWX_REGEX_FUNCTION}\\)${RWX_REGEX_OPEN}"
|
||||||
|
|
||||||
rwx_parse_code() {
|
rwx_parse_code() {
|
||||||
|
# parse aliases
|
||||||
|
local line
|
||||||
|
RWX_ALIASES="$(rwx_parse_aliases)"
|
||||||
|
while IFS= read -r line; do
|
||||||
|
eval "${line}"
|
||||||
|
done <<EOF
|
||||||
|
${RWX_ALIASES}
|
||||||
|
EOF
|
||||||
# parse constants
|
# parse constants
|
||||||
RWX_CONSTANTS="$(rwx_parse_constants)"
|
RWX_CONSTANTS="$(rwx_parse_constants)"
|
||||||
# parse functions
|
# parse functions
|
||||||
RWX_FUNCTIONS="$(rwx_parse_functions)"
|
RWX_FUNCTIONS="$(rwx_parse_functions)"
|
||||||
}
|
}
|
||||||
|
rwx_parse_aliases() {
|
||||||
|
printf "%s" "${_rwx_code}" |
|
||||||
|
awk \
|
||||||
|
--assign action="alias" \
|
||||||
|
--file "${RWX_AWK}"
|
||||||
|
}
|
||||||
rwx_parse_constants() {
|
rwx_parse_constants() {
|
||||||
printf "%s\n" "${RWX_CODE}" |
|
printf "%s\n" "${_rwx_code}" |
|
||||||
sed --silent "s|${RWX_REGEX_TARGET_CONSTANT}|\\1|p"
|
sed --silent "s|${RWX_REGEX_TARGET_CONSTANT}|\\1|p"
|
||||||
}
|
}
|
||||||
rwx_parse_functions() {
|
rwx_parse_functions() {
|
||||||
printf "%s\n" "${RWX_CODE}" |
|
printf "%s\n" "${_rwx_code}" |
|
||||||
sed --silent "s|${RWX_REGEX_TARGET_FUNCTION}|\\1|p"
|
sed --silent "s|${RWX_REGEX_TARGET_FUNCTION}|\\1|p"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -207,10 +225,12 @@ rwx_test() {
|
||||||
# TODO variables
|
# TODO variables
|
||||||
set \
|
set \
|
||||||
"main" \
|
"main" \
|
||||||
"self" \
|
"alias/git" \
|
||||||
\
|
\
|
||||||
"RWX_MAIN_NAME" \
|
"RWX_MAIN_NAME" \
|
||||||
\
|
\
|
||||||
|
"_rwx_code" \
|
||||||
|
\
|
||||||
"rwx_cache" \
|
"rwx_cache" \
|
||||||
\
|
\
|
||||||
"gsc"
|
"gsc"
|
||||||
|
|
|
@ -5,10 +5,11 @@
|
||||||
rwx_doc() {
|
rwx_doc() {
|
||||||
local name="${1}"
|
local name="${1}"
|
||||||
[ -n "${name}" ] || return
|
[ -n "${name}" ] || return
|
||||||
printf "%s" "${RWX_CODE}" |
|
printf "%s" "${_rwx_code}" |
|
||||||
awk \
|
awk \
|
||||||
-f "${RWX_ROOT_SYSTEM}/doc.awk" \
|
--assign action="doc" \
|
||||||
-v target="${name}"
|
--assign target="${name}" \
|
||||||
|
--file "${RWX_AWK}"
|
||||||
}
|
}
|
||||||
|
|
||||||
rwx_doc_old() {
|
rwx_doc_old() {
|
||||||
|
@ -55,7 +56,7 @@ rwx_doc_old() {
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
done <<EOF
|
done <<EOF
|
||||||
${RWX_CODE}
|
${_rwx_code}
|
||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue