Compare commits

...

20 commits

Author SHA1 Message Date
2f7dd63c74
code/awk
All checks were successful
/ job (push) Successful in 4m27s
2025-07-07 01:13:06 +02:00
be43cb7fe1
readme/tasks 2025-07-07 00:52:25 +02:00
a41d436657
fix 2025-07-07 00:43:19 +02:00
2a31766869
fix 2025-07-07 00:42:27 +02:00
98a46e246e
log/info 2025-07-07 00:40:25 +02:00
76e222c60d
test 2025-07-07 00:35:00 +02:00
77cb7d2bb1
test/code 2025-07-07 00:33:55 +02:00
060a84abda
test/doc 2025-07-07 00:29:50 +02:00
e157a1ecf7
code/aliases_commands 2025-07-07 00:17:58 +02:00
7d400d9031
code/variables 2025-07-07 00:01:06 +02:00
fed8a38bc1
main/deps 2025-07-07 00:00:06 +02:00
a40f086d10
−useless 2025-07-06 23:17:32 +02:00
4a2a24a1b6
code/check 2025-07-06 23:15:48 +02:00
d7bdca5f12
code/functions 2025-07-06 23:11:25 +02:00
abca96719b
code/constants 2025-07-06 23:10:52 +02:00
6b7598eb60
code 2025-07-06 23:09:41 +02:00
1dd525b86c
code/functions 2025-07-06 22:54:44 +02:00
8a6c02a262
code/constants 2025-07-06 22:52:08 +02:00
4c5ac91ac3
\ 2025-07-06 22:42:40 +02:00
b47e6ec7de
self/test 2025-07-06 22:39:57 +02:00
7 changed files with 144 additions and 104 deletions

View file

@ -117,5 +117,6 @@ Two interpreted languages for flexibility.
* get unresolved path for new panes & windows * get unresolved path for new panes & windows
* fully working doc function algorithm * fully working doc function algorithm
* self install aliases * self install aliases
* list aliases
### 6.2 [Further tasks](#when) {#when-further} ### 6.2 [Further tasks](#when) {#when-further}

70
sh/code.sh Normal file
View file

@ -0,0 +1,70 @@
# ╭──────╮
# │ 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}"
}

View file

@ -23,6 +23,8 @@ RWX_LOG_LEVEL=${RWX_LOG_LEVEL_INFO}
# │ log │ log │ # │ log │ log │
# ╰─────┴─────╯ # ╰─────┴─────╯
rwx_log() { rwx_log_info "${@}"; }
rwx_log_debug() { rwx_log_debug() {
if [ "${RWX_LOG_LEVEL}" -ge "${RWX_LOG_LEVEL_DEBUG}" ]; then if [ "${RWX_LOG_LEVEL}" -ge "${RWX_LOG_LEVEL_DEBUG}" ]; then
_rwx_log "[DEBUG]" "${@}" _rwx_log "[DEBUG]" "${@}"
@ -49,7 +51,6 @@ rwx_log_fatal() {
fi fi
} }
#= rwx_log
rwx_log_info() { rwx_log_info() {
if [ "${RWX_LOG_LEVEL}" -ge "${RWX_LOG_LEVEL_INFO}" ]; then if [ "${RWX_LOG_LEVEL}" -ge "${RWX_LOG_LEVEL_INFO}" ]; then
_rwx_log "" "${@}" _rwx_log "" "${@}"

View file

@ -3,6 +3,15 @@
# │ main │ # │ main │
# ╰──────╯ # ╰──────╯
# main module # main module
# * builtins
# * echo
# * printf
# * read
# * binaries
# * awk
# * cat
# * find
# * sed
# ╭──────┬───────────╮ # ╭──────┬───────────╮
# │ main │ constants │ # │ main │ constants │
@ -36,8 +45,6 @@ RWX_ROOT_SYSTEM="/usr/local/lib/${RWX_SELF_NAME}"
# user root directory of the project # user root directory of the project
RWX_SELF_USER="${HOME}/${RWX_SELF_NAME}" 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 # path to the entrypoint main file of the project
RWX_MAIN_PATH="${RWX_ROOT_SYSTEM}/${RWX_MAIN_NAME}" RWX_MAIN_PATH="${RWX_ROOT_SYSTEM}/${RWX_MAIN_NAME}"
@ -195,28 +202,28 @@ ${RWX_REGEX_BEGIN}\\(${RWX_REGEX_VARIABLE}\\)${RWX_REGEX_SET}"
_rwx_code_variables="" _rwx_code_variables=""
rwx_parse_code() { rwx_parse_code() {
# parse aliases # parse aliases commands
local line text local line text
RWX_ALIASES="$(rwx_parse_aliases)" _rwx_code_aliases_functions="$(rwx_parse_aliases_functions)"
while IFS= read -r line; do while IFS= read -r line; do
text="$(echo "${line}" | sed "s| |() { |")" text="$(echo "${line}" | sed "s| |() { |")"
text="${text} \"\${@}\"; }" text="${text} \"\${@}\"; }"
eval "${text}" eval "${text}"
done <<EOF done <<EOF
${RWX_ALIASES} ${_rwx_code_aliases_functions}
EOF EOF
# parse constants # parse constants
RWX_CONSTANTS="$(rwx_parse_constants)" _rwx_code_constants="$(rwx_parse_constants)"
# parse functions # parse functions
RWX_FUNCTIONS="$(rwx_parse_functions)" _rwx_code_functions="$(rwx_parse_functions)"
# parse variables # parse variables
_rwx_code_variables="$(rwx_parse_variables)" _rwx_code_variables="$(rwx_parse_variables)"
} }
rwx_parse_aliases() { rwx_parse_aliases_functions() {
printf "%s" "${_rwx_code}" | printf "%s" "${_rwx_code}" |
awk \ awk \
--assign action="alias" \ --assign action="alias" \
--file "${RWX_AWK}" "${_rwx_code_awk}"
} }
rwx_parse_constants() { rwx_parse_constants() {
printf "%s" "${_rwx_code}" | printf "%s" "${_rwx_code}" |
@ -231,31 +238,6 @@ rwx_parse_variables() {
sed --silent "s|${RWX_REGEX_TARGET_VARIABLE}|\\1|p" 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 │ # │ main │ run │
# ╰──────┴─────╯ # ╰──────┴─────╯

View file

@ -1,62 +1,6 @@
# self # self
# module # 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 │ # │ self │ commands │
# ╰──────┴──────────╯ # ╰──────┴──────────╯
@ -71,19 +15,6 @@ rwx_self_commands() {
sed "s|^${RWX_SELF_COMMAND}||" 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 │ # │ self │ help │
# ╰──────┴──────╯ # ╰──────┴──────╯

55
sh/test.sh Normal file
View file

@ -0,0 +1,55 @@
# ╭──────╮
# │ 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
}