baa-conductor

git clone 

baa-conductor / scripts
im_wower  ·  2026-03-29

git-snapshot.sh

 1#!/usr/bin/env bash
 2# git-snapshot.sh — generate static HTML for a git repo using stagit.
 3# Usage: git-snapshot.sh <repo_path> <output_dir>
 4#
 5# Supports incremental generation via stagit -c (cachefile).
 6
 7set -euo pipefail
 8
 9REPO_PATH="${1:?Usage: git-snapshot.sh <repo_path> <output_dir>}"
10OUTPUT_DIR="${2:?Usage: git-snapshot.sh <repo_path> <output_dir>}"
11
12# Resolve to absolute paths.
13REPO_PATH="$(cd "$REPO_PATH" && pwd)"
14
15# Ensure output directory exists.
16mkdir -p "$OUTPUT_DIR"
17OUTPUT_DIR="$(cd "$OUTPUT_DIR" && pwd)"
18
19CACHEFILE="$OUTPUT_DIR/.stagit-cache"
20
21# stagit must be run from the output directory.
22cd "$OUTPUT_DIR"
23
24# Generate static HTML (with incremental cache).
25stagit -c "$CACHEFILE" "$REPO_PATH"
26
27# Provide a minimal style.css if one doesn't exist yet.
28if [ ! -f "$OUTPUT_DIR/style.css" ]; then
29  cat > "$OUTPUT_DIR/style.css" <<'CSSEOF'
30body { font-family: monospace; margin: 1em; background: #fff; color: #222; }
31table { border-collapse: collapse; }
32td, th { padding: 2px 6px; }
33a { color: #005f87; }
34pre { overflow-x: auto; }
35hr { border: 0; border-top: 1px solid #ccc; }
36#content { overflow-x: auto; }
37.num { text-align: right; }
38CSSEOF
39fi
40
41# Create a 1x1 transparent PNG for logo/favicon if missing.
42if [ ! -f "$OUTPUT_DIR/logo.png" ]; then
43  printf '\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x01\x00\x00\x00\x01\x08\x06\x00\x00\x00\x1f\x15\xc4\x89\x00\x00\x00\nIDATx\x9cc\x00\x01\x00\x00\x05\x00\x01\r\n\xb4\x00\x00\x00\x00IEND\xaeB`\x82' > "$OUTPUT_DIR/logo.png"
44fi
45if [ ! -f "$OUTPUT_DIR/favicon.png" ]; then
46  cp "$OUTPUT_DIR/logo.png" "$OUTPUT_DIR/favicon.png"
47fi
48
49echo "stagit: generated static HTML in $OUTPUT_DIR"