set-active-plan.sh 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #!/bin/sh
  2. # planning-with-files: set or display the active plan pointer.
  3. #
  4. # Usage:
  5. # set-active-plan.sh <plan_id> — pin .planning/.active_plan to plan_id
  6. # set-active-plan.sh — print the current active plan (if any)
  7. #
  8. # The active plan is stored in .planning/.active_plan and is read by
  9. # resolve-plan-dir.sh when no $PLAN_ID env var is set.
  10. set -e
  11. PLAN_ROOT="${PWD}/.planning"
  12. ACTIVE_FILE="${PLAN_ROOT}/.active_plan"
  13. # No args → show current active plan
  14. if [ "${1:-}" = "" ]; then
  15. if [ -f "${ACTIVE_FILE}" ]; then
  16. plan_id="$(tr -d '\r\n' < "${ACTIVE_FILE}")"
  17. if [ -n "${plan_id}" ] && [ -d "${PLAN_ROOT}/${plan_id}" ]; then
  18. echo "Active plan: ${plan_id}"
  19. echo "Path: ${PLAN_ROOT}/${plan_id}"
  20. elif [ -n "${plan_id}" ]; then
  21. echo "Active plan pointer: ${plan_id} (directory not found — stale pointer)"
  22. else
  23. echo "No active plan set."
  24. fi
  25. else
  26. echo "No active plan set."
  27. fi
  28. exit 0
  29. fi
  30. PLAN_ID="$1"
  31. PLAN_DIR="${PLAN_ROOT}/${PLAN_ID}"
  32. if [ ! -d "${PLAN_DIR}" ]; then
  33. echo "Error: plan directory not found: ${PLAN_DIR}" >&2
  34. echo "Run: init-session.sh \"${PLAN_ID}\" to create it, or check .planning/ for available plans." >&2
  35. exit 1
  36. fi
  37. mkdir -p "${PLAN_ROOT}"
  38. printf "%s\n" "${PLAN_ID}" > "${ACTIVE_FILE}"
  39. echo "Active plan set to: ${PLAN_ID}"
  40. echo "Path: ${PLAN_DIR}"
  41. echo ""
  42. echo "To pin this terminal session only:"
  43. echo " export PLAN_ID=${PLAN_ID}"