#!/usr/bin/env bash # Install a git pre-commit hook that runs BibGuard in --quick mode whenever # the staged changes touch .bib or .tex files. # # Usage (run from the repo root that contains your paper, NOT BibGuard's repo): # bash /path/to/BibGuard/scripts/install-hook.sh # # Skip the hook for one commit: git commit --no-verify set -euo pipefail if ! git rev-parse --git-dir >/dev/null 2>&1; then echo "Error: not inside a git repo." >&2 exit 1 fi HOOK_DIR="$(git rev-parse --git-dir)/hooks" HOOK="$HOOK_DIR/pre-commit" # Locate BibGuard's main.py — we assume this script lives in BibGuard/scripts/. BIBGUARD_DIR="$(cd "$(dirname "$0")/.." && pwd)" MAIN_PY="$BIBGUARD_DIR/main.py" if [[ ! -f "$MAIN_PY" ]]; then echo "Error: cannot locate BibGuard main.py at $MAIN_PY" >&2 exit 1 fi mkdir -p "$HOOK_DIR" if [[ -f "$HOOK" ]]; then echo "A pre-commit hook already exists at $HOOK" echo "Backing it up to $HOOK.bibguard-backup" mv "$HOOK" "$HOOK.bibguard-backup" fi cat >"$HOOK" <