Project Files
auto-commit.sh
#!/usr/bin/env bash
# auto-commit.sh — commits all pending changes in playbookDirectory.
#
# Config source: ~/.lmstudio/.internal/global-plugin-configs.json
# key: ceveyne/playbook → fields → playbookDirectory
# Falls back to ~/Documents/Playbook if not set (matches config.ts default).
#
# Intended to be called periodically via launchd (see com.ceveyne.playbook-auto-commit.plist).
# No fswatch/chokidar dependency — just runs, commits if dirty, exits.
set -euo pipefail
DEFAULT_DIR="$HOME/Documents/Playbook"
LMSTUDIO_CONFIG="$HOME/.lmstudio/.internal/global-plugin-configs.json"
# ── Resolve target directory from LM Studio plugin config ────────────────────
PLAYBOOK_DIR="$(python3 - <<'PYEOF'
import json, os, sys
config_path = os.path.expanduser("~/.lmstudio/.internal/global-plugin-configs.json")
default = os.path.join(os.path.expanduser("~"), "Documents", "Playbook")
try:
with open(config_path) as f:
data = json.load(f)
plugins = data.get("json", {}).get("plugins", [])
for entry in plugins:
if isinstance(entry, list) and len(entry) == 2 and entry[0] == "ceveyne/playbook":
for field in entry[1].get("fields", []):
if field.get("key") == "playbookDirectory" and field.get("value", "").strip():
print(field["value"].strip())
sys.exit(0)
except Exception:
pass
print(default)
PYEOF
)"
if [[ -z "$PLAYBOOK_DIR" ]]; then
echo "[auto-commit] ERROR: Could not determine playbook directory." >&2
exit 1
fi
echo "[auto-commit] Directory: $PLAYBOOK_DIR"
# ── Init git if missing ───────────────────────────────────────────────────────
init_git_if_needed() {
local dir="$1"
if [[ ! -d "$dir/.git" ]]; then
echo "[auto-commit] No git repo found in $dir — initialising..."
git -C "$dir" init -b main
git -C "$dir" add -A
git -C "$dir" commit -m "init: initial commit"
echo "[auto-commit] Git repo initialised."
fi
}
# ── Commit if dirty, then exit ────────────────────────────────────────────────
init_git_if_needed "$PLAYBOOK_DIR"
git -C "$PLAYBOOK_DIR" add -A
if ! git -C "$PLAYBOOK_DIR" diff --cached --quiet; then
git -C "$PLAYBOOK_DIR" commit -m "auto: $(date '+%Y-%m-%dT%H:%M:%S')"
echo "[auto-commit] Committed at $(date '+%H:%M:%S')"
else
echo "[auto-commit] Nothing to commit."
fi