Last active
August 29, 2016 00:18
-
-
Save thcipriani/e56cdef56a98eb0cf7e93dadf94fbdd8 to your computer and use it in GitHub Desktop.
Add exif info about git-annex managed photos in git-notes under the namespace "pictures"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -eu | |
COMMAND='' | |
usage() { | |
cat<<HELP | |
usage: git photo <add|show|rm> <file> | |
HELP | |
} | |
do_rm() { | |
local sum="$1" | |
set -x | |
git notes --ref=pictures remove "$sum" | |
set +x | |
} | |
do_show() { | |
local sum="$1" | |
set -x | |
git notes --ref=pictures show "$sum" | |
set +x | |
} | |
do_add() { | |
local sum="$1" | |
local exif | |
# Explode if exiftool isn't a thing | |
command -v exiftool &>/dev/null | |
exif=$(exiftool -S \ | |
-filename \ | |
-filetypeextension \ | |
-make \ | |
-model \ | |
-lensid \ | |
-focallength \ | |
-fnumber \ | |
-iso "$file") | |
set -x | |
git notes --ref=pictures add -m "$exif" "$sum" | |
set +x | |
} | |
main() { | |
subcommand="$1" | |
shift | |
for cmd in 'add' 'show' 'rm'; do | |
if [[ "$subcommand" == "$cmd" ]]; then | |
COMMAND="do_${cmd}" | |
fi | |
done | |
if [[ -z "$COMMAND" ]]; then | |
usage | |
exit 1 | |
fi | |
for file in "$@"; do | |
content=$( readlink "$file" ) | |
sum=$( printf 'blob %s\0%s' "${#content}" "$content" | sha1sum ) | |
sum="${sum:0:32}" | |
$COMMAND "$sum" | |
done | |
} | |
main "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment