From 4c862481f77ca1c127556a9efaf65b51f529896a Mon Sep 17 00:00:00 2001 From: Marc Beninca Date: Mon, 25 Nov 2024 22:21:01 +0100 Subject: [PATCH] main/source_dir --- sh/main.sh | 62 ++++++++++++++++++++++++++---------------------------- 1 file changed, 30 insertions(+), 32 deletions(-) diff --git a/sh/main.sh b/sh/main.sh index bc3fecc..6c18b48 100644 --- a/sh/main.sh +++ b/sh/main.sh @@ -38,34 +38,6 @@ _sh_main_log() { esac } -# sort - -main_source_directory() { - local path="${1}" - [ -d "${path}" ] || - return 1 - local cmd count module modules - modules="$(sh_find_sh "${path}" "${SH_MAIN_NAME}")" - _sh_ifs_new - count=0 - _sh_main_log "" \ - ". ${path}" - for module in ${modules}; do - count=$((count + 1)) - _sh_main_log "$(printf "%02d" "${count}") ${module%.sh}" - module="${path}/${module}" - # shellcheck disable=SC1090 - . "${module}" - cmd="$(sh_grep_functions "${module}")" - if [ -n "${cmd}" ]; then - [ -n "${CMD}" ] && CMD="${CMD} -" - CMD="${CMD}${cmd}" - fi - done - _sh_ifs_pop -} - # public sh_find_extension() { @@ -102,18 +74,44 @@ sh_help() { "u__… = user" } +sh_source_directory() { + local path="${1}" + [ -d "${path}" ] || + return 1 + local cmd count module modules + modules="$(sh_find_sh "${path}" "${SH_MAIN_NAME}")" + _sh_ifs_new + count=0 + _sh_main_log "" \ + ". ${path}" + for module in ${modules}; do + count=$((count + 1)) + _sh_main_log "$(printf "%02d" "${count}") ${module%.sh}" + module="${path}/${module}" + # shellcheck disable=SC1090 + . "${module}" + cmd="$(sh_grep_functions "${module}")" + if [ -n "${cmd}" ]; then + [ -n "${CMD}" ] && CMD="${CMD} +" + CMD="${CMD}${cmd}" + fi + done + _sh_ifs_pop +} + +# main + sh_main() { - if ! main_source_directory "${SH_ROOT}"; then + if ! sh_source_directory "${SH_ROOT}"; then _sh_main_log "Not a directory: ${SH_ROOT}" return 1 fi - main_source_directory "${SH_USER}" + sh_source_directory "${SH_USER}" sh_log sh_shellcheck "${SH_ROOT}" sh_log sh_help } -# main - sh_main