Skip to content

Instantly share code, notes, and snippets.

@Cosmicist
Forked from wrboyce/gist:786460
Created October 9, 2012 17:05
Show Gist options
  • Save Cosmicist/3860074 to your computer and use it in GitHub Desktop.
Save Cosmicist/3860074 to your computer and use it in GitHub Desktop.
pre-commit hook to automatically minify javascript/css
#!/bin/bash
# Search YUI Compressor anywhere in your home dir
echo "Searching for YUI Compressor..."
YUIC=`find ~/. -type f -name yuicompressor\*.jar`
if ! [ $YUIC ]
then
echo "Unable to find YUI Compressor! Goodbye!"
exit
fi
echo -e "YUI Compressor found! Start compressing...\n"
function _c
{
fname=$(basename "$1")
dest=$(dirname "$1")
ext="${fname##*.}"
dest_fname="$dest/${fname%.*}.min.$ext"
echo "Compressing $1..."
java -jar $YUIC $1 > $dest_fname
git add $dest_fname
echo "Done."
echo ""
}
for file in $(find -E . -iregex '.*\.(js|css)$' -and -not -iregex '.*\.min\.(js|css)$');
do
_c $file
done
echo "That is all."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment