this repo has no description
1#!/bin/bash
2# Finds and prints the latest plan (or one matching a query)
3# Usage: latest-plan.sh [query]
4# No args: prints the highest-numbered plan
5# With query: finds plans matching the query (by number or name)
6
7set -euo pipefail
8
9PLANS_DIR=".claude/plans"
10
11if [[ ! -d "$PLANS_DIR" ]]; then
12 echo "No plans directory found at $PLANS_DIR" >&2
13 exit 1
14fi
15
16# Check if any .md files exist (macOS/BSD compatible)
17if [[ -z "$(find "$PLANS_DIR" -maxdepth 1 -name '*.md' -print -quit 2>/dev/null)" ]]; then
18 echo "No plans found in $PLANS_DIR" >&2
19 exit 1
20fi
21
22if [[ -z "${1:-}" ]]; then
23 # No query - get the highest numbered plan
24 LATEST=$(find "$PLANS_DIR" -maxdepth 1 -name '*.md' -exec basename {} \; \
25 | grep -E '^[0-9]{4}-' \
26 | sort -n \
27 | tail -1 || true)
28 if [[ -n "$LATEST" ]]; then
29 cat "$PLANS_DIR/$LATEST"
30 else
31 echo "No numbered plans found" >&2
32 exit 1
33 fi
34else
35 # Query provided - search by number or name
36 QUERY="$1"
37 MATCH=$(find "$PLANS_DIR" -maxdepth 1 -name '*.md' -exec basename {} \; \
38 | grep -iE "$QUERY" \
39 | sort -n \
40 | tail -1 || true)
41 if [[ -n "$MATCH" ]]; then
42 cat "$PLANS_DIR/$MATCH"
43 else
44 echo "No plan matching '$QUERY' found" >&2
45 exit 1
46 fi
47fi