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