2014-12-05

I've created a rudimentary Git diff driver for Anki decks. It's not pretty, but it's more informative than the opaque β€œbinary files differ” message.

#!/bin/bash
# # Installation
#
# .gitattributes:
#
# *.apkg diff=apkg
#
# .gitconfig:
#
# [diff "apkg"]
# textconv = <path to this script>
# cachetextconv = true
set -Eeuo pipefail

apkg_path="$1"

# Filenames and checksums of package contents
unzip -lv "$apkg_path" | grep --invert-match '^Archive:\s'
echo

# Database dump
db_path="$(mktemp -p "/run/user/$UID")"; trap 'rm "$db_path"' EXIT
unzip -p "$apkg_path" 'collection.anki2' > "$db_path"
sqlite3 "$db_path" '.dump'