wip/path
This commit is contained in:
parent
ba5d740362
commit
6ce158712d
1 changed files with 22 additions and 15 deletions
|
@ -10,37 +10,44 @@ main_link_bashrc() {
|
|||
ln --symbolic "${MAIN_USERS_FILE}" "${file}"
|
||||
}
|
||||
|
||||
# import modules
|
||||
main_import_modules() {
|
||||
local file="${1}"
|
||||
if [ -f "${file}" ]; then
|
||||
local count ifs module modules path root
|
||||
path="$(realpath --canonicalize-existing "${file}")"
|
||||
root="$(dirname "${path}")"
|
||||
modules="$(find "${root}" -type "f" -name "*.sh" -printf "%P
|
||||
main_import_directory() {
|
||||
local path="${1}"
|
||||
if [ -d "${path}" ]; then
|
||||
local count ifs module modules
|
||||
modules="$(find "${path}" -type "f" -name "*.sh" -printf "%P
|
||||
" | sort)"
|
||||
ifs="${IFS}"
|
||||
IFS="
|
||||
"
|
||||
count=0
|
||||
echo
|
||||
echo ". ${root}"
|
||||
echo ". ${path}"
|
||||
for module in ${modules}; do
|
||||
count=$((count + 1))
|
||||
printf "%02d" "${count}"
|
||||
echo " ${module%.sh}"
|
||||
module="${root}/${module}"
|
||||
if [ "${module}" != "${path}" ]; then
|
||||
module="${path}/${module}"
|
||||
if [ "${module}" != "${ENV}" ]; then
|
||||
. "${module}"
|
||||
fi
|
||||
done
|
||||
IFS="${ifs}"
|
||||
return 0
|
||||
else
|
||||
log_fatal "No file: ${file}"
|
||||
echo "Not a directory: ${path}"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
main_import_modules "${ENV}"
|
||||
main_import_modules ~/shell/main.sh
|
||||
main_import_file() {
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue