dotfiles/.local/bin/universal_run.sh

39 lines
844 B
Bash
Raw Normal View History

2026-03-09 00:07:31 -04:00
#!/usr/bin/env bash
set -eo pipefail
2026-03-14 17:32:02 -04:00
readonly SCRIPT="${BASH_SOURCE[0]}"
2026-03-09 00:07:31 -04:00
fail() {
2026-03-14 17:32:02 -04:00
printf "ERR - %s: %s\n" "$SCRIPT" "$1" >&2
2026-03-09 00:07:31 -04:00
exit 1
}
2026-03-14 17:32:02 -04:00
DIR="${1:-$(pwd)}"
if [[ ! -d "$DIR" ]]; then
printf "Usage: %s <Project Directory>\n" "$SCRIPT"
2026-03-09 00:07:31 -04:00
exit 1
fi
2026-03-14 17:32:02 -04:00
(
cd "$DIR" || fail "Couldn't enter directory: $DIR"
if [[ -x "./run.sh" ]]; then
./run.sh || fail "run.sh failed"
2026-03-09 00:07:31 -04:00
elif [[ -f "Cargo.toml" ]]; then
2026-03-14 17:32:02 -04:00
cargo run || fail "Cargo execution failed"
elif [[ -f "Makefile" ]]; then
EXEC=$(awk -F '=' '/^TARGET[[:space:]]*=/ {print $2}' Makefile | xargs)
if [[ -z "$EXEC" ]]; then
fail "Makefile found, but no 'TARGET' variable defined."
fi
make && ./"$EXEC" || fail "Make build or execution failed"
else
fail "No recognized entry point (run.sh, Cargo.toml, or Makefile) found."
2026-03-09 00:07:31 -04:00
fi
2026-03-14 17:32:02 -04:00
)