Skip to content

Instantly share code, notes, and snippets.

@allolex
Last active December 11, 2015 07:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save allolex/4564357 to your computer and use it in GitHub Desktop.
Save allolex/4564357 to your computer and use it in GitHub Desktop.
Improved code for snapping photos when committing to a git repo
#!/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"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment