This commit is contained in:
Marc Beninca 2024-11-29 19:25:49 +01:00
parent 4335005aac
commit 903faba54e
Signed by: marc.beninca
GPG key ID: 9C7613450C80C24F

View file

@ -16,19 +16,25 @@ SH_MAIN="${SH_ROOT}/${SH_MAIN_NAME}"
SH_SHELL="$(cat "/proc/${$}/comm")" SH_SHELL="$(cat "/proc/${$}/comm")"
SH_USER="${HOME}/${SH_NAME}" SH_USER="${HOME}/${SH_NAME}"
# ╭──────────╮
# │ internal │
# ╰──────────╯
# _RWX_IFS
# ╭─────────╮ # ╭─────────╮
# │ private │ # │ private │
# ╰─────────╯ # ╰─────────╯
_sh_ifs_new() { rwx_ifs_set() {
SH_IFS="${IFS}" _RWX_IFS="${IFS}"
IFS=" IFS="
" "
} }
_sh_ifs_pop() { rwx_ifs_unset() {
IFS="${SH_IFS}" IFS="${_RWX_IFS}"
unset SH_IFS unset RWX_IFS
} }
_rwx_main_log() { _rwx_main_log() {
@ -46,7 +52,7 @@ _rwx_main_log() {
# ╰────────╯ # ╰────────╯
# find directory’s files by extension # find directory’s files by extension
sh_find_extension() { rwx_find_extension() {
local extension="${1}" local extension="${1}"
local root="${2}" local root="${2}"
local file="${3}" local file="${3}"
@ -64,12 +70,12 @@ sh_find_extension() {
} }
# find directory’s sh files # find directory’s sh files
sh_find_sh() { rwx_find_sh() {
sh_find_extension "sh" "${@}" rwx_find_extension "sh" "${@}"
} }
# get functions from file # get functions from file
sh_grep_functions() { rwx_grep_functions() {
local file="${1}" local file="${1}"
grep "()" "${file}" | grep "()" "${file}" |
cut --delimiter "(" --fields 1 cut --delimiter "(" --fields 1
@ -77,8 +83,8 @@ sh_grep_functions() {
# output help message # output help message
rwx_help() { rwx_help() {
sh_log \ rwx_log \
"sh_… = shell functions" \ "rwx_… = functions" \
" a__… = aliases" \ " a__… = aliases" \
" u__… = user" " u__… = user"
} }
@ -96,8 +102,8 @@ rwx_main_source() {
[ -d "${path}" ] || [ -d "${path}" ] ||
return 1 return 1
local cmd count module modules local cmd count module modules
modules="$(sh_find_sh "${path}" "${SH_MAIN_NAME}")" modules="$(rwx_find_sh "${path}" "${SH_MAIN_NAME}")"
_sh_ifs_new rwx_ifs_set
count=0 count=0
_rwx_main_log "" \ _rwx_main_log "" \
". ${path}" ". ${path}"
@ -107,14 +113,14 @@ rwx_main_source() {
module="${path}/${module}" module="${path}/${module}"
# shellcheck disable=SC1090 # shellcheck disable=SC1090
. "${module}" . "${module}"
cmd="$(sh_grep_functions "${module}")" cmd="$(rwx_grep_functions "${module}")"
if [ -n "${cmd}" ]; then if [ -n "${cmd}" ]; then
[ -n "${CMD}" ] && CMD="${CMD} [ -n "${CMD}" ] && CMD="${CMD}
" "
CMD="${CMD}${cmd}" CMD="${CMD}${cmd}"
fi fi
done done
_sh_ifs_pop rwx_ifs_unset
} }
# ╭──────╮ # ╭──────╮
@ -133,13 +139,13 @@ rwx_main() {
# run interactive extras # run interactive extras
if rwx_shell_interactive; then if rwx_shell_interactive; then
# check format # check format
sh_log rwx_log
rwx_shfmt_check "${SH_ROOT}" rwx_shfmt_check "${SH_ROOT}"
# check syntax # check syntax
sh_log rwx_log
rwx_shellcheck_check "${SH_ROOT}" rwx_shellcheck_check "${SH_ROOT}"
# help # help
sh_log rwx_log
rwx_help rwx_help
fi fi
} }