Compare commits
No commits in common. "1467c1158a31d8d9408b21f573bfe7cd6c2fc2bb" and "b0afca09a56e3046a2e218911eb1efac7190959e" have entirely different histories.
1467c1158a
...
b0afca09a5
5 changed files with 91 additions and 139 deletions
|
@ -1,5 +1,3 @@
|
||||||
# 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
Normal file
83
sh/doc.awk
Normal file
|
@ -0,0 +1,83 @@
|
||||||
|
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
108
sh/main.awk
|
@ -1,108 +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_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,7 +32,6 @@ 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}"
|
||||||
|
|
||||||
# ╭──────┬──────╮
|
# ╭──────┬──────╮
|
||||||
|
@ -65,9 +64,6 @@ 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() {
|
||||||
|
@ -78,7 +74,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}
|
||||||
"
|
"
|
||||||
|
@ -185,31 +181,17 @@ 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"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -225,12 +207,10 @@ rwx_test() {
|
||||||
# TODO variables
|
# TODO variables
|
||||||
set \
|
set \
|
||||||
"main" \
|
"main" \
|
||||||
"alias/git" \
|
"self" \
|
||||||
\
|
\
|
||||||
"RWX_MAIN_NAME" \
|
"RWX_MAIN_NAME" \
|
||||||
\
|
\
|
||||||
"_rwx_code" \
|
|
||||||
\
|
|
||||||
"rwx_cache" \
|
"rwx_cache" \
|
||||||
\
|
\
|
||||||
"gsc"
|
"gsc"
|
||||||
|
|
|
@ -5,11 +5,10 @@
|
||||||
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 \
|
||||||
--assign action="doc" \
|
-f "${RWX_ROOT_SYSTEM}/doc.awk" \
|
||||||
--assign target="${name}" \
|
-v target="${name}"
|
||||||
--file "${RWX_AWK}"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
rwx_doc_old() {
|
rwx_doc_old() {
|
||||||
|
@ -56,7 +55,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