Skip to content

Instantly share code, notes, and snippets.

@tombh
Created December 4, 2024 15:06
Show Gist options
  • Save tombh/178ae9bb3ccb4b09cdc6017beda3156d to your computer and use it in GitHub Desktop.
Save tombh/178ae9bb3ccb4b09cdc6017beda3156d to your computer and use it in GitHub Desktop.
A lightweight BASH-only Make replacement
#!/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