Skip to content

Instantly share code, notes, and snippets.

@asaaki
Last active December 11, 2015 12:58
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 asaaki/4603721 to your computer and use it in GitHub Desktop.
Save asaaki/4603721 to your computer and use it in GitHub Desktop.
Exports *.bmml files to PNGs when staged for git commit
#!/bin/sh
# .git/hooks/pre-commit
#
# NEEDS registered version of Balsamiq Mockups (mandatory for PNG export)
#
# Exports *.bmml files to PNGs, but only for new or modified ones (files in stage area).
# This should be installed as .git/hooks/pre-commit in your local repository (with +x flag).
# As git hook it ensures that your new/modified (and staged) files will be exported before commit
# your changes to the repository automatically.
#
# INSTALL
#
# $ cd /to/your/repo/with/mockups
# $ curl https://gist.github.com/raw/4603721/pre-commit -o .git/hooks/pre-commit
# $ chmod +x .git/hooks/pre-commit
#
# USAGE
#
# * Edit/create your mockups
# * Prepare commit and `git add` the files you want to commit (stage them!)
# * Commit -> the hook is triggered and creates the PNGs
# for OSX only:
mockupsApp="/Applications/Balsamiq Mockups.app/Contents/MacOS/Balsamiq Mockups"
cdir=`pwd`
files=`git diff HEAD --cached --name-only | awk '$0~/bmml/{print}' | sed -e 's/ /%20/g'`
for f in $files; do
ifile=`echo ${cdir}/${f} | sed -e 's/%20/\\\ /g'`
ofile=`echo $ifile | sed -e 's/bmml/png/'`
echo "Converting"
echo " $ifile"
echo " to $ofile"
`"$mockupsApp" export "$ifile" "$ofile"`
done
# Hm, you should not need to use this with a proper BM app setup ...
# exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment