This commit is contained in:
Marc Beninca 2024-11-15 19:02:22 +01:00
parent ba5d740362
commit 6ce158712d
Signed by: marc.beninca
GPG key ID: 9C7613450C80C24F

View file

@ -10,37 +10,44 @@ main_link_bashrc() {
ln --symbolic "${MAIN_USERS_FILE}" "${file}" ln --symbolic "${MAIN_USERS_FILE}" "${file}"
} }
# import modules main_import_directory() {
main_import_modules() { local path="${1}"
local file="${1}" if [ -d "${path}" ]; then
if [ -f "${file}" ]; then local count ifs module modules
local count ifs module modules path root modules="$(find "${path}" -type "f" -name "*.sh" -printf "%P
path="$(realpath --canonicalize-existing "${file}")"
root="$(dirname "${path}")"
modules="$(find "${root}" -type "f" -name "*.sh" -printf "%P
" | sort)" " | sort)"
ifs="${IFS}" ifs="${IFS}"
IFS=" IFS="
" "
count=0 count=0
echo echo
echo ". ${root}" echo ". ${path}"
for module in ${modules}; do for module in ${modules}; do
count=$((count + 1)) count=$((count + 1))
printf "%02d" "${count}" printf "%02d" "${count}"
echo " ${module%.sh}" echo " ${module%.sh}"
module="${root}/${module}" module="${path}/${module}"
if [ "${module}" != "${path}" ]; then if [ "${module}" != "${ENV}" ]; then
. "${module}" . "${module}"
fi fi
done done
IFS="${ifs}" IFS="${ifs}"
return 0
else else
log_fatal "No file: ${file}" echo "Not a directory: ${path}"
return 1 return 1
fi fi
} }
main_import_modules "${ENV}" main_import_file() {
main_import_modules ~/shell/main.sh local path="${1}"
if [ -f "${path}" ]; then
main_import_directory "$(dirname "${path}")"
else
echo "Not a file: ${path}"
return 1
fi
}
main_import_file "${ENV}"
main_import_directory ~/shell