Last active
December 11, 2015 07:09
-
-
Save allolex/4564357 to your computer and use it in GitHub Desktop.
Improved code for snapping photos when committing to a git repo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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