Skip to content

Instantly share code, notes, and snippets.

@WillBrubaker
Created June 8, 2014 14:40
Show Gist options
  • Save WillBrubaker/c9bdae8c77a1b3a60167 to your computer and use it in GitHub Desktop.
Save WillBrubaker/c9bdae8c77a1b3a60167 to your computer and use it in GitHub Desktop.
A pre-commit hook to minify css & js when committing to branch 'master'
#!/bin/sh
#
# A pre-commit hook to minify js & css files
# if committing to branch 'master'
BRANCH=`git rev-parse --abbrev-ref HEAD`
if [ "$BRANCH" == 'master' ]
then
csspath='css/*.css'
jspath='js/*.js'
for file in $csspath
do
echo $file | grep '[.|-]min.css' > /dev/null
MINIMIZED=$?
if [ "$MINIMIZED" != 0 ]
then
if [[ "$file" =~ .css$ ]]
then
minfile=`basename "$file" .css`.min.css
rm -f css/"$minfile"
/usr/local/bin/yuicompressor --type css -o css/"$minfile" $file
git add $minfile
fi
fi
done
for file in $jspath
do
echo $file | grep '[.|-]min.js' > /dev/null
MINIMIZED=$?
if [ "$MINIMIZED" != 0 ]
then
if [[ "$file" =~ .js$ ]]
then
minfile=`basename "$file" .js`.min.js
rm -rf js/"$minfile"
/usr/local/bin/yuicompressor --type js -o js/"$minfile" $file
git add $minfile
fi
fi
done
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment