Skip to content

Instantly share code, notes, and snippets.

@wrboyce
Created January 19, 2011 17:12
Show Gist options
  • Star 13 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save wrboyce/786460 to your computer and use it in GitHub Desktop.
Save wrboyce/786460 to your computer and use it in GitHub Desktop.
pre-commit hook to automatically minify javascript/css
#!/usr/bin/zsh
COMPRESSOR=$(whence -p yui-compressor)
[ -z $COMPRESSOR ] && exit 0;
function _compress {
local fname=$1:t
local dest_path=$1:h
local min_fname="$dest_path/${fname:r}.min.${fname:e}"
$COMPRESSOR $1 > $min_fname
git add $min_fname
}
for file in $(find . -regextype posix-extended -iregex '.+\.(css|js)$' -and -not -iregex '.+\.min\.(css|js)$'); _compress $file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment