imagesnap git post-commit photo rewrite
Remember the tip for git that takes an image of each commit via git's built-in hooks? (The one that takes a photo of you when you make a commit.) Here's a somewhat cleaner rewrite of post-commit—just because it's a shell script doesn't mean it has to be ugly.
To keep things tidy, it creates a folder called commit_images directly in your repo and gitignores it for you. It then adds the commit photos to that folder.
imagesnap can be installed under OS X via homebrew.
Here's the gist
#!/bin/bash
function make_image_dir () {
TARGET_DIR=$1
if [ ! -d "${TARGET_DIR}" ]; then
mkdir "${TARGET_DIR}"
fi
}
function ignore_image_dir () {
TARGET_DIR=$1
GIT_IGNORE=$2
grep -q "${TARGET_DIR}" "${GIT_IGNORE}"
if [ $? -gt 0 ]; then
echo "${TARGET_DIR}" >> "${GIT_IGNORE}"
fi
}
function take_photo () {
TARGET_DIR=$1
DATE_STRING=`date '+%Y_%m_%d-%H_%M_%S'`
imagesnap -q "${TARGET_DIR}/${USER}-${DATE_STRING}.jpg"
}
BASE_DIR=$GIT_DIR/..
IMAGE_DIR=commit_images
make_image_dir "$BASE_DIR/$IMAGE_DIR"
ignore_image_dir "$IMAGE_DIR" "$BASE_DIR/.gitignore"
take_photo "$BASE_DIR/$IMAGE_DIR"
Written by Damon Davison
Related protips
5 Responses
You didn't tell us what it takes a picture of. I had to look at the docs for imagesnap.
For others: this script takes a photo of you via webcam.
Shortened version of the script: https://gist.github.com/4564682
@mislav I've added a parenthetical comment for people like yourself who don't know about or remember the original conversation this tip came from.
@mislav What's the benefit of the shorter script?
Absolutely no benefit, except that I find shorter = easier to read.
@mislav Heh. This is a case of reasonable minds disagreeing. I wrote it this way so people could follow along more easily. Basically the same reason as you. :)