-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbeet-hook-diff-cli_exit
More file actions
executable file
·44 lines (33 loc) · 1.01 KB
/
Copy pathbeet-hook-diff-cli_exit
File metadata and controls
executable file
·44 lines (33 loc) · 1.01 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
44
#!/usr/bin/env bash
: "${TMPDIR:=/tmp}"
: "${XDG_CONFIG_HOME:=${HOME}/.config}"
: "${BEETS_LIBRARY=$XDG_CONFIG_HOME/beets/library.db}"
: "${DIFF:-}"
: "${DIFF:=diff -u --color}"
set -euo pipefail
session="$TMPDIR/beets/hook-diff-$PPID"
if ! [[ -e "$session/library.sql.before" ]]; then
printf 'error: %s does not exit; was the pluginload hook ran?\n' \
"$session/library.sql.before" \
>&2
exit 127
fi
sha1sum "$BEETS_LIBRARY" | cut -c1-40 >"$session/after.sha1sum"
e=0
if [[ "$(<"$session/before.sha1sum")" != "$(<"$session/after.sha1sum")" ]]; then
(
sqlite3 -readonly -batch \
"$BEETS_LIBRARY" \
'.dump' \
>"$session/library.sql.after"
eval "${DIFF}" -- "$session/library.sql.before" "$session/library.sql.after" || :
) || e=$?
fi
beets_sessions_count=$(pgrep -c beet)
sessions=("${session%/*}"/hook-diff-*)
if [[ "${#sessions[@]}" -ne "$beets_sessions_count" ]]; then
rm -rf "${sessions[@]}"
else
rm -rf "$session"
fi
exit "$e"