-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdot-sync
More file actions
executable file
·38 lines (31 loc) · 919 Bytes
/
dot-sync
File metadata and controls
executable file
·38 lines (31 loc) · 919 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
33
34
35
36
37
38
#!/usr/bin/env bash
set -eo pipefail
ERROR_LOG="$(mktemp)"
GIT=(
"/usr/bin/git"
"--git-dir=$HOME/.dotfiles/.git"
"--work-tree=$HOME"
)
function notify_on_error {
if command -v notify-send >/dev/null; then
notify-send --app-name="dot-sync" \
"Failed to sync dotfiles." \
"$(tr '\n' ' ' <"$ERROR_LOG" | tr -s '[:space:]')"
else
>&2 cat "$ERROR_LOG"
fi
}
trap 'notify_on_error' EXIT
cd "$HOME" 2>"$ERROR_LOG"
"${GIT[@]}" pull -q origin master >/dev/null 2>"$ERROR_LOG"
if command -v pacman >/dev/null; then
pacman -Qqe >.arch.conf 2>"$ERROR_LOG"
fi
if command -v ripsecrets >/dev/null; then
ripsecrets --strict-ignore $("${GIT[@]}" diff --name-only --diff-filter=ACM) >"$ERROR_LOG" 2>&1
fi
if [ -n "$("${GIT[@]}" status --short)" ]; then
"${GIT[@]}" commit --quiet -am "Auto-sync $(date)" 2>"$ERROR_LOG" --no-verify
fi
"${GIT[@]}" push -q origin master 2>"$ERROR_LOG" --no-verify
trap - EXIT