-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathvault.sh
More file actions
executable file
·43 lines (39 loc) · 1.17 KB
/
Copy pathvault.sh
File metadata and controls
executable file
·43 lines (39 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env bash
# vault.sh - git sync helper for a brainstack vault.
#
# Usage:
# vault.sh sync [message] # commit + push (auto message if omitted)
# vault.sh status # git status of the vault
# vault.sh log # last 10 commits
#
# Config:
# BRAINSTACK_VAULT env var (default: ~/vault)
set -euo pipefail
VAULT="${BRAINSTACK_VAULT:-$HOME/vault}"
if [[ ! -d "$VAULT/.git" ]]; then
echo "no git repo at $VAULT - init with: cd \"$VAULT\" && git init && git add -A && git commit -m init" >&2
exit 1
fi
cmd="${1:-status}"
shift || true
case "$cmd" in
sync)
msg="${1:-brainstack sync $(date +%Y-%m-%d)}"
(cd "$VAULT" && git add -A && git diff --cached --quiet || git commit -m "$msg")
# push only if a remote exists; never fail the sync on offline
if (cd "$VAULT" && git remote -v | grep -q push); then
(cd "$VAULT" && git push) 2>/dev/null || echo "push skipped (offline?)" >&2
fi
echo "vault synced: $msg"
;;
status)
(cd "$VAULT" && git status --short | head -50)
;;
log)
(cd "$VAULT" && git log --oneline -10)
;;
*)
echo "unknown command: $cmd (use sync|status|log)" >&2
exit 2
;;
esac