Skip to content

Instantly share code, notes, and snippets.

@miku
Last active August 29, 2015 14:01
Show Gist options
  • Save miku/111bb2c029ffe89475d7 to your computer and use it in GitHub Desktop.
Save miku/111bb2c029ffe89475d7 to your computer and use it in GitHub Desktop.
Git pre-commit hook, taking a screenshot of a single webpage
#!/usr/bin/env bash
HOMEPAGE=http://localhost:5000
SCREENIE_DIR=$(pwd)/screenshots
HEAD=$(git rev-parse HEAD)
if [[ "$OSTYPE" == "darwin"* ]]; then
RESPONSE=$(curl --write-out %{http_code} --silent --output /dev/null "$HOMEPAGE")
if [[ "$RESPONSE" == 200 ]]; then
mkdir -p "$SCREENIE_DIR"
OUTPUT="$(date +'%s')-$HEAD.png"
webkit2png --dir "$SCREENIE_DIR" -o "$OUTPUT" "$HOMEPAGE"
git add "$SCREENIE_DIR"
exit 0
else
echo "Stopping. Please start the server manually,"
echo "so we can take our photograph. Or run 'git commit --no-verify'"
echo "$HOMEPAGE response was $RESPONSE"
exit 1
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment