#!/bin/bash
# Print a prompt file from $OLLIE_PROMPTS_PATH to stdout.
# Usage: prime <name>  (resolves <name> or <name>.md under OLLIE_PROMPTS_PATH)
# Resolution and variable expansion is now handled by the Go prompt resolver;
# this script is a convenience wrapper for manual/CLI use.
set -euo pipefail

PROMPTS_PATH="${OLLIE_PROMPTS_PATH:-${HOME}/.config/ollie/prompts}"

if [ $# -ne 1 ]; then
    echo "usage: prime <name>" >&2
    exit 1
fi

NAME="$1"

IFS=: read -ra DIRS <<< "$PROMPTS_PATH"
for dir in "${DIRS[@]}"; do
    [ -z "$dir" ] && continue
    for path in "$dir/$NAME" "$dir/$NAME.md"; do
        if [ -f "$path" ]; then
            cat "$path"
            exit 0
        fi
    done
done

echo "prime: prompt not found: $NAME" >&2
exit 1
