Last active
April 6, 2022 13:00
-
-
Save ar2pi/d19869c5ba2b2b42601124939593ae89 to your computer and use it in GitHub Desktop.
Bash module loader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# | |
# A simple bash script to execute all adjacent scripts | |
# | |
# Usage: | |
# source /path/to/all.sh | |
# OR | |
# . /path/to/all.sh | |
# | |
# Options: | |
# -v|--verbose: verbose output | |
# | |
function main () { | |
local CURRENT_SCRIPT_DIR=$(dirname ${BASH_SOURCE[0]}) | |
local CURRENT_SCRIPT_FILE=$(basename ${BASH_SOURCE[0]}) | |
local modules=$(ls -1 $CURRENT_SCRIPT_DIR | grep -v $CURRENT_SCRIPT_FILE) | |
local is_verbose=$([[ ! -z ${1+_} && ($1 = "-v" || $1 = "--verbose") ]] && echo "1" || echo "0") | |
for module in $modules; do | |
if [[ -f $CURRENT_SCRIPT_DIR/$module ]]; then | |
. $CURRENT_SCRIPT_DIR/$module | |
if [[ $is_verbose = 1 ]]; then | |
echo "Loaded $CURRENT_SCRIPT_DIR/$module" | |
fi | |
fi | |
done | |
} | |
main "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment