2024-11-17 21:27:05 +00:00
|
|
|
[ -n "${ENV}" ] || export ENV="/etc/sh/main.sh"
|
2024-11-15 15:43:48 +00:00
|
|
|
|
2024-11-17 17:11:25 +00:00
|
|
|
main_commands() {
|
|
|
|
local file="${1}"
|
2024-11-17 20:46:01 +00:00
|
|
|
grep "()" "${file}" |
|
2024-11-17 17:11:25 +00:00
|
|
|
cut --delimiter "(" --fields 1
|
|
|
|
}
|
|
|
|
|
2024-11-15 18:06:14 +00:00
|
|
|
main_source_directory() {
|
2024-11-15 18:02:22 +00:00
|
|
|
local path="${1}"
|
|
|
|
if [ -d "${path}" ]; then
|
2024-11-17 17:11:25 +00:00
|
|
|
local cmd count ifs module modules
|
2024-11-15 18:10:40 +00:00
|
|
|
modules="$(find "${path}" \
|
|
|
|
-type "f" \
|
|
|
|
-name "*.sh" \
|
|
|
|
-printf "%P
|
2024-11-13 11:50:49 +00:00
|
|
|
" | sort)"
|
2024-11-13 11:41:37 +00:00
|
|
|
ifs="${IFS}"
|
|
|
|
IFS="
|
|
|
|
"
|
2024-11-13 13:55:20 +00:00
|
|
|
count=0
|
|
|
|
echo
|
2024-11-15 18:02:22 +00:00
|
|
|
echo ". ${path}"
|
2024-11-13 11:41:37 +00:00
|
|
|
for module in ${modules}; do
|
2024-11-13 13:55:20 +00:00
|
|
|
count=$((count + 1))
|
|
|
|
printf "%02d" "${count}"
|
|
|
|
echo " ${module%.sh}"
|
2024-11-15 18:02:22 +00:00
|
|
|
module="${path}/${module}"
|
|
|
|
if [ "${module}" != "${ENV}" ]; then
|
2024-11-12 09:14:08 +00:00
|
|
|
. "${module}"
|
2024-11-17 17:11:25 +00:00
|
|
|
cmd="$(main_commands "${module}")"
|
2024-11-17 17:17:06 +00:00
|
|
|
if [ -n "${cmd}" ]; then
|
|
|
|
[ -n "${CMD}" ] && CMD="${CMD}
|
|
|
|
"
|
|
|
|
CMD="${CMD}${cmd}"
|
|
|
|
fi
|
2024-11-12 09:14:08 +00:00
|
|
|
fi
|
|
|
|
done
|
2024-11-13 11:41:37 +00:00
|
|
|
IFS="${ifs}"
|
2024-11-17 17:11:25 +00:00
|
|
|
log_info
|
|
|
|
log_info "${CMD}"
|
2024-11-12 09:14:08 +00:00
|
|
|
else
|
2024-11-15 18:02:22 +00:00
|
|
|
echo "Not a directory: ${path}"
|
2024-11-12 09:14:08 +00:00
|
|
|
return 1
|
|
|
|
fi
|
2023-05-09 20:15:40 +00:00
|
|
|
}
|
2023-05-09 20:09:01 +00:00
|
|
|
|
2024-11-15 18:06:14 +00:00
|
|
|
main_source_file() {
|
2024-11-15 18:02:22 +00:00
|
|
|
local path="${1}"
|
|
|
|
if [ -f "${path}" ]; then
|
2024-11-15 18:11:16 +00:00
|
|
|
main_source_directory "$(dirname "${path}")"
|
2024-11-15 18:02:22 +00:00
|
|
|
else
|
|
|
|
echo "Not a file: ${path}"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2024-11-15 18:06:14 +00:00
|
|
|
main_source_file "${ENV}"
|
2024-11-15 18:02:22 +00:00
|
|
|
|
2024-11-17 14:40:29 +00:00
|
|
|
main_source_directory "${HOME}/shell"
|