#!/usr/bin/env bash # scripts/cap.sh — wrap a command with hard timeout. Hang = FAIL. # Picks gtimeout (mac coreutils) or timeout (linux). # Usage: cap.sh [args...] set -euo pipefail TIMEOUT_BIN=gtimeout command -v gtimeout >/dev/null 2>&1 || TIMEOUT_BIN=timeout if ! command -v "$TIMEOUT_BIN" >/dev/null 2>&1; then echo "ERROR: need 'timeout' or 'gtimeout'" >&2 exit 2 fi secs="$1"; shift exec "$TIMEOUT_BIN" --signal=KILL "$secs" "$@"