60 lines
1.1 KiB
Bash
60 lines
1.1 KiB
Bash
[ -n "${ENV}" ] || export ENV="/etc/shell/main.sh"
|
|
|
|
main_commands() {
|
|
local file="${1}"
|
|
grep "()" "${file}" |
|
|
cut --delimiter "(" --fields 1
|
|
}
|
|
|
|
main_source_directory() {
|
|
local path="${1}"
|
|
if [ -d "${path}" ]; then
|
|
local cmd count ifs module modules
|
|
modules="$(find "${path}" \
|
|
-type "f" \
|
|
-name "*.sh" \
|
|
-printf "%P
|
|
" | sort)"
|
|
ifs="${IFS}"
|
|
IFS="
|
|
"
|
|
count=0
|
|
echo
|
|
echo ". ${path}"
|
|
for module in ${modules}; do
|
|
count=$((count + 1))
|
|
printf "%02d" "${count}"
|
|
echo " ${module%.sh}"
|
|
module="${path}/${module}"
|
|
if [ "${module}" != "${ENV}" ]; then
|
|
. "${module}"
|
|
cmd="$(main_commands "${module}")"
|
|
if [ -n "${cmd}" ]; then
|
|
[ -n "${CMD}" ] && CMD="${CMD}
|
|
"
|
|
CMD="${CMD}${cmd}"
|
|
fi
|
|
fi
|
|
done
|
|
IFS="${ifs}"
|
|
log_info
|
|
log_info "${CMD}"
|
|
else
|
|
echo "Not a directory: ${path}"
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
main_source_file() {
|
|
local path="${1}"
|
|
if [ -f "${path}" ]; then
|
|
main_source_directory "$(dirname "${path}")"
|
|
else
|
|
echo "Not a file: ${path}"
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
main_source_file "${ENV}"
|
|
|
|
main_source_directory "${HOME}/shell"
|