Created
December 4, 2024 15:06
-
-
Save tombh/178ae9bb3ccb4b09cdc6017beda3156d to your computer and use it in GitHub Desktop.
A lightweight BASH-only Make replacement
This file contains hidden or 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 | |
# This is my personal approach to "Make" files (or `just`, etc). | |
# | |
# I put it in the root of a project and run it with: `./ctl.sh the_name_of_a_function` | |
# Where the function name is any function found in `./scripts/*.bash`. | |
set -e | |
export PROJECT_ROOT | |
function_to_run=$1 | |
PROJECT_ROOT=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd) | |
function _includes_path { | |
echo "$PROJECT_ROOT"/scripts | |
} | |
function _load_includes { | |
for file in "$(_includes_path)"/*.bash; do | |
# shellcheck source=/dev/null | |
source "$file" | |
done | |
} | |
_load_includes | |
if [[ $(type -t "$function_to_run") != function ]]; then | |
echo "Subcommand: '$function_to_run' not found." | |
exit 1 | |
fi | |
shift | |
_pushd "$PROJECT_ROOT" | |
"$function_to_run" "$@" | |
_popd |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment