Skip to content

Instantly share code, notes, and snippets.

@pbojinov
Forked from allolex/gist:4564357
Last active April 8, 2018 02:33
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save pbojinov/6260266 to your computer and use it in GitHub Desktop.
imagesnap git post-commit photo rewrite
#!/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"
echo "got a pic of you coding :)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment