-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcsync.sh
More file actions
32 lines (28 loc) · 782 Bytes
/
Copy pathcsync.sh
File metadata and controls
32 lines (28 loc) · 782 Bytes
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
#!/usr/bin/env bash
# Sync cursor-sync: stage, commit if needed, pull --rebase, push.
# Source from ~/.bashrc or ~/.zshrc: source ~/cursor-sync/scripts/csync.sh
# Or run once: ~/cursor-sync/scripts/csync.sh "optional message"
_cursor_sync_repo() {
if [[ -n "${CURSOR_SYNC:-}" ]]; then
printf '%s' "$CURSOR_SYNC"
else
cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd
fi
}
csync() {
local msg="${1:-sync $(date -u +"%Y-%m-%dT%H:%M:%SZ")}"
local repo
repo="$(_cursor_sync_repo)" || return 1
(
cd "$repo" || exit 1
git add -A
if ! git diff --cached --quiet; then
git commit -m "$msg"
fi
git pull --rebase --autostash --quiet
git push --quiet
)
}
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
csync "$@"
fi