Skip to content

Instantly share code, notes, and snippets.

@tombh
Last active April 3, 2026 15:17
Show Gist options
  • Select an option

  • Save tombh/178ae9bb3ccb4b09cdc6017beda3156d to your computer and use it in GitHub Desktop.

Select an option

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
@skvale

skvale commented Apr 3, 2026

Copy link
Copy Markdown

I'm guessing you intended to include these

_pushd () {
    command pushd "$@" > /dev/null
}

_popd () {
    command popd "$@" > /dev/null
}

@tombh

tombh commented Apr 3, 2026

Copy link
Copy Markdown
Author

Oh! Yes good point. For this gist then I just remove the custom push/pop functions and use native pushd and popd. Thanks for letting me know :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment