Compare commits
No commits in common. "2f7dd63c7464c20815f4edb62e523fc937a4c522" and "58b0919a7c6ce7aa5c080e02d366368611bb8614" have entirely different histories.
2f7dd63c74
...
58b0919a7c
7 changed files with 104 additions and 144 deletions
|
@ -117,6 +117,5 @@ Two interpreted languages for flexibility.
|
|||
* get unresolved path for new panes & windows
|
||||
* fully working doc function algorithm
|
||||
* self install aliases
|
||||
* list aliases
|
||||
|
||||
### 6.2 [Further tasks](#when) {#when-further}
|
||||
|
|
70
sh/code.sh
70
sh/code.sh
|
@ -1,70 +0,0 @@
|
|||
# ╭──────╮
|
||||
# │ code │
|
||||
# ╰──────╯
|
||||
|
||||
# ╭──────┬───────────╮
|
||||
# │ code │ variables │
|
||||
# ╰──────┴───────────╯
|
||||
|
||||
# path to the required parsing awk script
|
||||
_rwx_code_awk="$(cat "${RWX_ROOT_SYSTEM}/code.awk")"
|
||||
|
||||
# ╭──────┬───────╮
|
||||
# │ code │ parts │
|
||||
# ╰──────┴───────╯
|
||||
|
||||
# show the cached code
|
||||
#= rc
|
||||
rwx_code() {
|
||||
echo "${_rwx_code}"
|
||||
}
|
||||
|
||||
# show the cached aliases and functions
|
||||
#= rcaf
|
||||
rwx_code_aliases_functions() {
|
||||
echo "${_rwx_code_aliases_functions}"
|
||||
}
|
||||
|
||||
# show the cached constants
|
||||
#= rcc
|
||||
rwx_code_constants() {
|
||||
echo "${_rwx_code_constants}"
|
||||
}
|
||||
|
||||
# show the cached functions
|
||||
#= rcf
|
||||
rwx_code_functions() {
|
||||
echo "${_rwx_code_functions}"
|
||||
}
|
||||
|
||||
# show the cached variables
|
||||
#= rcv
|
||||
rwx_code_variables() {
|
||||
echo "${_rwx_code_variables}"
|
||||
}
|
||||
|
||||
# ╭──────┬───────╮
|
||||
# │ code │ parse │
|
||||
# ╰──────┴───────╯
|
||||
|
||||
# check source code
|
||||
rwx_code_check() {
|
||||
# check format
|
||||
rwx_log
|
||||
rwx_shfmt "${RWX_ROOT_SYSTEM}"
|
||||
# check syntax
|
||||
rwx_log
|
||||
rwx_shellcheck "${RWX_ROOT_SYSTEM}"
|
||||
}
|
||||
|
||||
# fetch matching doc for given name
|
||||
#= rcd
|
||||
rwx_code_doc() {
|
||||
local name="${1}"
|
||||
[ -n "${name}" ] || return
|
||||
printf "%s" "${_rwx_code}" |
|
||||
awk \
|
||||
--assign action="doc" \
|
||||
--assign target="${name}" \
|
||||
"${_rwx_code_awk}"
|
||||
}
|
|
@ -23,8 +23,6 @@ RWX_LOG_LEVEL=${RWX_LOG_LEVEL_INFO}
|
|||
# │ log │ log │
|
||||
# ╰─────┴─────╯
|
||||
|
||||
rwx_log() { rwx_log_info "${@}"; }
|
||||
|
||||
rwx_log_debug() {
|
||||
if [ "${RWX_LOG_LEVEL}" -ge "${RWX_LOG_LEVEL_DEBUG}" ]; then
|
||||
_rwx_log "[DEBUG]" "${@}"
|
||||
|
@ -51,6 +49,7 @@ rwx_log_fatal() {
|
|||
fi
|
||||
}
|
||||
|
||||
#= rwx_log
|
||||
rwx_log_info() {
|
||||
if [ "${RWX_LOG_LEVEL}" -ge "${RWX_LOG_LEVEL_INFO}" ]; then
|
||||
_rwx_log "" "${@}"
|
||||
|
|
50
sh/main.sh
50
sh/main.sh
|
@ -3,15 +3,6 @@
|
|||
# │ main │
|
||||
# ╰──────╯
|
||||
# main module
|
||||
# * builtins
|
||||
# * echo
|
||||
# * printf
|
||||
# * read
|
||||
# * binaries
|
||||
# * awk
|
||||
# * cat
|
||||
# * find
|
||||
# * sed
|
||||
|
||||
# ╭──────┬───────────╮
|
||||
# │ main │ constants │
|
||||
|
@ -45,6 +36,8 @@ RWX_ROOT_SYSTEM="/usr/local/lib/${RWX_SELF_NAME}"
|
|||
# user root directory of the project
|
||||
RWX_SELF_USER="${HOME}/${RWX_SELF_NAME}"
|
||||
|
||||
# path to the required parsing awk script
|
||||
RWX_AWK="${RWX_ROOT_SYSTEM}/${RWX_MAIN_NAME%.sh}.awk"
|
||||
# path to the entrypoint main file of the project
|
||||
RWX_MAIN_PATH="${RWX_ROOT_SYSTEM}/${RWX_MAIN_NAME}"
|
||||
|
||||
|
@ -202,28 +195,28 @@ ${RWX_REGEX_BEGIN}\\(${RWX_REGEX_VARIABLE}\\)${RWX_REGEX_SET}"
|
|||
_rwx_code_variables=""
|
||||
|
||||
rwx_parse_code() {
|
||||
# parse aliases commands
|
||||
# parse aliases
|
||||
local line text
|
||||
_rwx_code_aliases_functions="$(rwx_parse_aliases_functions)"
|
||||
RWX_ALIASES="$(rwx_parse_aliases)"
|
||||
while IFS= read -r line; do
|
||||
text="$(echo "${line}" | sed "s| |() { |")"
|
||||
text="${text} \"\${@}\"; }"
|
||||
eval "${text}"
|
||||
done <<EOF
|
||||
${_rwx_code_aliases_functions}
|
||||
${RWX_ALIASES}
|
||||
EOF
|
||||
# parse constants
|
||||
_rwx_code_constants="$(rwx_parse_constants)"
|
||||
RWX_CONSTANTS="$(rwx_parse_constants)"
|
||||
# parse functions
|
||||
_rwx_code_functions="$(rwx_parse_functions)"
|
||||
RWX_FUNCTIONS="$(rwx_parse_functions)"
|
||||
# parse variables
|
||||
_rwx_code_variables="$(rwx_parse_variables)"
|
||||
}
|
||||
rwx_parse_aliases_functions() {
|
||||
rwx_parse_aliases() {
|
||||
printf "%s" "${_rwx_code}" |
|
||||
awk \
|
||||
--assign action="alias" \
|
||||
"${_rwx_code_awk}"
|
||||
--file "${RWX_AWK}"
|
||||
}
|
||||
rwx_parse_constants() {
|
||||
printf "%s" "${_rwx_code}" |
|
||||
|
@ -238,6 +231,31 @@ rwx_parse_variables() {
|
|||
sed --silent "s|${RWX_REGEX_TARGET_VARIABLE}|\\1|p"
|
||||
}
|
||||
|
||||
# ╭──────┬──────╮
|
||||
# │ main │ test │
|
||||
# ╰──────┴──────╯
|
||||
|
||||
#= rt
|
||||
rwx_test() {
|
||||
local item
|
||||
set \
|
||||
"main" \
|
||||
"alias/git" \
|
||||
\
|
||||
"RWX_MAIN_NAME" \
|
||||
\
|
||||
"_rwx_code" \
|
||||
\
|
||||
"rwx_cache" \
|
||||
\
|
||||
"alias/batcat" \
|
||||
"b"
|
||||
for item in "${@}"; do
|
||||
echo
|
||||
rwx_doc "${item}"
|
||||
done
|
||||
}
|
||||
|
||||
# ╭──────┬─────╮
|
||||
# │ main │ run │
|
||||
# ╰──────┴─────╯
|
||||
|
|
69
sh/self.sh
69
sh/self.sh
|
@ -1,6 +1,62 @@
|
|||
# self
|
||||
# module
|
||||
|
||||
# show the cached code
|
||||
#= rc
|
||||
rwx_code() {
|
||||
echo "${_rwx_code}"
|
||||
}
|
||||
|
||||
# show the cached aliases
|
||||
#= rca
|
||||
rwx_code_aliases() {
|
||||
echo "${RWX_ALIASES}"
|
||||
}
|
||||
|
||||
# show the cached constants
|
||||
#= rcc
|
||||
rwx_code_constants() {
|
||||
echo "${RWX_CONSTANTS}"
|
||||
}
|
||||
|
||||
# show the cached functions
|
||||
#= rcf
|
||||
rwx_code_functions() {
|
||||
echo "${RWX_FUNCTIONS}"
|
||||
}
|
||||
|
||||
# show the cached variables
|
||||
#= rcv
|
||||
rwx_code_variables() {
|
||||
echo "${_rwx_code_variables}"
|
||||
}
|
||||
|
||||
# meta doc
|
||||
#= rd
|
||||
rwx_doc() {
|
||||
local name="${1}"
|
||||
[ -n "${name}" ] || return
|
||||
printf "%s" "${_rwx_code}" |
|
||||
awk \
|
||||
--assign action="doc" \
|
||||
--assign target="${name}" \
|
||||
--file "${RWX_AWK}"
|
||||
}
|
||||
|
||||
# ╭──────┬───────╮
|
||||
# │ self │ check │
|
||||
# ╰──────┴───────╯
|
||||
|
||||
# check source code
|
||||
rwx_self_check() {
|
||||
# check format
|
||||
rwx_log
|
||||
rwx_shfmt "${RWX_ROOT_SYSTEM}"
|
||||
# check syntax
|
||||
rwx_log
|
||||
rwx_shellcheck "${RWX_ROOT_SYSTEM}"
|
||||
}
|
||||
|
||||
# ╭──────┬──────────╮
|
||||
# │ self │ commands │
|
||||
# ╰──────┴──────────╯
|
||||
|
@ -15,6 +71,19 @@ rwx_self_commands() {
|
|||
sed "s|^${RWX_SELF_COMMAND}||"
|
||||
}
|
||||
|
||||
# ╭──────┬───────────╮
|
||||
# │ self │ functions │
|
||||
# ╰──────┴───────────╯
|
||||
|
||||
# get functions from root
|
||||
rwx_self_functions() {
|
||||
grep \
|
||||
--directories "recurse" \
|
||||
--no-filename \
|
||||
"()" "${RWX_ROOT_SYSTEM}" |
|
||||
cut --delimiter "(" --fields 1
|
||||
}
|
||||
|
||||
# ╭──────┬──────╮
|
||||
# │ self │ help │
|
||||
# ╰──────┴──────╯
|
||||
|
|
55
sh/test.sh
55
sh/test.sh
|
@ -1,55 +0,0 @@
|
|||
# ╭──────╮
|
||||
# │ test │
|
||||
# ╰──────╯
|
||||
# * code
|
||||
# * doc
|
||||
|
||||
rwx_test() {
|
||||
rwx_test_code
|
||||
rwx_test_doc
|
||||
}
|
||||
|
||||
# ╭──────┬──────╮
|
||||
# │ test │ code │
|
||||
# ╰──────┴──────╯
|
||||
|
||||
rwx_test_code() {
|
||||
local items
|
||||
set \
|
||||
"constants" \
|
||||
"variables" \
|
||||
"functions" \
|
||||
"aliases_functions" \
|
||||
"aliases" \
|
||||
|
||||
rwx_code
|
||||
for items in "${@}"; do
|
||||
echo
|
||||
"rwx_code_${items}"
|
||||
done
|
||||
}
|
||||
|
||||
# ╭──────┬─────╮
|
||||
# │ test │ doc │
|
||||
# ╰──────┴─────╯
|
||||
|
||||
rwx_test_doc() {
|
||||
local item
|
||||
set \
|
||||
"main" \
|
||||
"alias/git" \
|
||||
\
|
||||
"RWX_MAIN_NAME" \
|
||||
\
|
||||
"_rwx_code" \
|
||||
\
|
||||
"rwx_cache" \
|
||||
\
|
||||
"alias/batcat" \
|
||||
"b" \
|
||||
|
||||
for item in "${@}"; do
|
||||
echo
|
||||
rwx_code_doc "${item}"
|
||||
done
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue