Git status output contains ## which was being interpreted as bash. Split render() into quoted heredocs + echo statements.
138 lines
2.2 KiB
Bash
Executable file
138 lines
2.2 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
usage() {
|
|
cat <<'USAGE'
|
|
Usage: handoff.sh --goal "short goal" [--output /path/to/handoff.md]
|
|
|
|
Options:
|
|
-g, --goal Short goal description (required)
|
|
-o, --output Write output to file (optional; defaults to stdout)
|
|
-h, --help Show this help
|
|
USAGE
|
|
}
|
|
|
|
GOAL=""
|
|
OUTPUT=""
|
|
|
|
while [[ $# -gt 0 ]]; do
|
|
case "$1" in
|
|
-g|--goal)
|
|
if [[ $# -lt 2 || "$2" == -* ]]; then
|
|
echo "Error: --goal requires a value" >&2
|
|
usage
|
|
exit 1
|
|
fi
|
|
GOAL="$2"
|
|
shift 2
|
|
;;
|
|
-o|--output)
|
|
if [[ $# -lt 2 || "$2" == -* ]]; then
|
|
echo "Error: --output requires a path" >&2
|
|
usage
|
|
exit 1
|
|
fi
|
|
OUTPUT="$2"
|
|
shift 2
|
|
;;
|
|
-h|--help)
|
|
usage
|
|
exit 0
|
|
;;
|
|
*)
|
|
echo "Error: unknown argument '$1'" >&2
|
|
usage
|
|
exit 1
|
|
;;
|
|
esac
|
|
done
|
|
|
|
if [[ -z "$GOAL" ]]; then
|
|
echo "Error: --goal is required" >&2
|
|
usage
|
|
exit 1
|
|
fi
|
|
|
|
if ! command -v git >/dev/null; then
|
|
echo "Error: git is required" >&2
|
|
exit 1
|
|
fi
|
|
|
|
repo_root=""
|
|
branch=""
|
|
status=""
|
|
diff_stat=""
|
|
recent_commits=""
|
|
|
|
if git rev-parse --show-toplevel >/dev/null 2>&1; then
|
|
repo_root=$(git rev-parse --show-toplevel)
|
|
branch=$(git branch --show-current || true)
|
|
status=$(git status --short --branch)
|
|
diff_stat=$(git diff --stat)
|
|
recent_commits=$(git log --oneline -5)
|
|
fi
|
|
|
|
timestamp=$(date -Iseconds)
|
|
|
|
render() {
|
|
cat <<'HEADER'
|
|
# Handoff Summary
|
|
|
|
HEADER
|
|
echo "**Goal:** $GOAL"
|
|
echo ""
|
|
echo "**Timestamp:** $timestamp"
|
|
cat <<'MIDDLE'
|
|
|
|
## Current State
|
|
|
|
- [ ] Summary of what is already done
|
|
- [ ] Notable decisions made
|
|
|
|
## Next Steps
|
|
|
|
- [ ] Step 1
|
|
- [ ] Step 2
|
|
|
|
## Open Questions
|
|
|
|
- [ ] Question 1
|
|
|
|
## Repository Context
|
|
|
|
MIDDLE
|
|
echo "**Repo Root:** ${repo_root:-"(not in git repo)"}"
|
|
echo "**Branch:** ${branch:-"(unknown)"}"
|
|
cat <<'GITHEADER'
|
|
|
|
### Git Status
|
|
|
|
```
|
|
GITHEADER
|
|
echo "${status:-"(no git status available)"}"
|
|
cat <<'DIFFHEADER'
|
|
```
|
|
|
|
### Diff Summary
|
|
|
|
```
|
|
DIFFHEADER
|
|
echo "${diff_stat:-"(no changes)"}"
|
|
cat <<'COMMITSHEADER'
|
|
```
|
|
|
|
### Recent Commits
|
|
|
|
```
|
|
COMMITSHEADER
|
|
echo "${recent_commits:-"(no commits found)"}"
|
|
echo '```'
|
|
}
|
|
|
|
if [[ -n "$OUTPUT" ]]; then
|
|
render > "$OUTPUT"
|
|
echo "Wrote handoff to $OUTPUT"
|
|
else
|
|
render
|
|
fi
|