Skip to content

Instantly share code, notes, and snippets.

@thcipriani
Last active August 29, 2016 00:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thcipriani/e56cdef56a98eb0cf7e93dadf94fbdd8 to your computer and use it in GitHub Desktop.
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"
#!/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