Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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