#!/usr/bin/env bash
# packs/tmuxinator/install-020-templates.sh -- seed project templates.
#
# Mutates: creates ~/.config/tmuxinator/ and COPIES templates/*.template into
# it (dropping the .template suffix) ONLY where no file of that name exists.
# Copies, not symlinks, deliberately: project files are user-edited working
# documents; a re-install must never clobber them.
#
# Usage: bash install-020-templates.sh   [TOOLKIT_DRY_RUN=1 to preview]
# Exit codes: 0 PROCEED, 1 HOLD, 2 precondition missing. ASCII + LF.

set -euo pipefail
shopt -s inherit_errexit 2>/dev/null || true
IFS=$'\n\t'
PACK_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
. "$PACK_DIR/../../lib/lib-install.sh"

CFG_DIR="$HOME/.config/tmuxinator"
ensure_dir "$CFG_DIR"

found=0
for t in "$PACK_DIR"/templates/*.template; do
    [ -f "$t" ] || continue
    found=1
    base=$(basename "$t" .template)
    copy_if_absent "$t" "$CFG_DIR/$base"
done
if [ "$found" -eq 0 ]; then
    fail "no templates found in $PACK_DIR/templates"
    exit 2
fi
info "start a project with: tmuxinator start <name>"
