Last active
August 29, 2015 14:05
-
-
Save bencaron/d04f4da7a90fdc125a32 to your computer and use it in GitHub Desktop.
SASS -> CSS pre-commit hook
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Watch for changes in the $SASS_DIR | |
# If anything change, compile the sass files to css | |
SASS_DIR="sass/" | |
STAGED=`git diff --cached --name-only` | |
echo $STAGED | if grep --quiet "$SASS_DIR" | |
then | |
echo Compiling and adding to the commit your SASS files... | |
for sassfile in "$STAGED" ; do | |
cssfile="${sassfile//sass/css}" | |
echo sass $sassfile $cssfile | |
sass $sassfile $cssfile | |
wait $! | |
git add $cssfile | |
done | |
fi |
Author
bencaron
commented
Sep 9, 2014
Check and act only on sass
#!/bin/bash
# Watch for changes in the $SASS_DIR
# If anything change, compile the sass files to css
CSS_DIR="css"
SASS_DIR="css/sass"
STAGED=`git diff --cached --name-only`
echo $STAGED | if grep --quiet "$SASS_DIR"
then
echo Compiling and adding to the commit your SASS files...
for sassfile in "$STAGED" ; do
if [[ $sassfile =~ \.sass$ ]]; then
cssfilename=`basename $sassfile`
cssfile=$CSS_DIR/${cssfilename//sass/css}
echo sass $sassfile $cssfile
sass $sassfile $cssfile
wait $!
git add $cssfile
fi
done
fi
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment