#! /usr/bin/env sh # ╭──────╮ # │ main │ # ╰──────╯ # ╭──────┬───────────╮ # │ main │ constants │ # ╰──────┴───────────╯ # project parent directory RWX_MAIN_PARENT="/usr/local/lib" # project name RWX_MAIN_NAME="rwx" # project entrypoint module RWX_MAIN_MODULE="main" # shell modules extension RWX_MAIN_EXTENSION="sh" # ╭──────┬───────────╮ # │ main │ variables │ # ╰──────┴───────────╯ # project main root directory rwx_main_root="${RWX_MAIN_PARENT}/${RWX_MAIN_NAME}" # project main entrypoint file rwx_main_file="${RWX_MAIN_MODULE}/${RWX_MAIN_EXTENSION}" # path to the entrypoint main file of the project rwx_main_path="${rwx_main_root}/${rwx_main_file}" # ╭──────┬──────╮ # │ main │ find │ # ╰──────┴──────╯ # FIXME separate in two functions # find root directory shell modules #| find #| sed #| sort rwx_main_find() { local root="${1}" [ -d "${root}" ] && find \ "${root}" \ -name "*.${RWX_MAIN_EXTENSION}" \ -type "f" \ -printf "%P\n" | sed "s|\\.[^.]*\$||" | sort } # ╭──────┬──────╮ # │ main │ main │ # ╰──────┴──────╯ # run required initial steps #< core/code #< core/shell rwx_main_main() { local module local modules # find main modules modules="$(rwx_main_find "${rwx_main_root}")" # source main modules while IFS= read -r module; do # except currently running main module if [ "${module}" != "${RWX_MAIN_MODULE}" ]; then # shellcheck disable=SC1090 . "${rwx_main_root}/${module}.${RWX_MAIN_EXTENSION}" fi done <