~kris/dots

srice

ref: b42b72dc2648499470b89418ac629e40f41d3149 srice/.local/bin/backup-ms -rwxr-xr-x 756 bytes
b42b72dc — Kris Yotam sb-battery: match macsmc-battery by type, add low-battery dunst alerts; xprofile: caps:super 2 months ago
                                                                                
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
#!/usr/bin/env bash
# backup-ms -- git snapshot of manuscript with dated tag
set -euo pipefail

dir="${1:-.}"
msg="${2:-snapshot}"

cd "$dir"

if ! git rev-parse --is-inside-work-tree &>/dev/null; then
    echo "Not a git repository. Initializing..."
    git init
    git add -A
    git commit -m "Initial manuscript commit"
fi

# Stage everything
git add -A

# Check for changes
if git diff --cached --quiet 2>/dev/null; then
    echo "No changes to snapshot."
    exit 0
fi

tag="ms-$(date +%Y%m%d-%H%M)"
words=$(find . -name '*.md' -o -name '*.mdx' -o -name '*.txt' 2>/dev/null | xargs cat 2>/dev/null | wc -w)

git commit -m "$msg ($words words)"
git tag "$tag"

echo "Snapshot: $tag"
echo "Words: $words"
echo "Commit: $(git log -1 --format='%h %s')"