Skip to content

Instantly share code, notes, and snippets.

@bencaron
Last active August 29, 2015 14:05
Show Gist options
  • Save bencaron/d04f4da7a90fdc125a32 to your computer and use it in GitHub Desktop.
Save bencaron/d04f4da7a90fdc125a32 to your computer and use it in GitHub Desktop.
SASS -> CSS pre-commit hook
#!/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
@bencaron
Copy link
Author

bencaron commented Sep 9, 2014

CSSFILENAME=basename $sassfile
cssfile=$CSS_DIR/${CSSFILENAME//sass/css}

@bencaron
Copy link
Author

bencaron commented Sep 9, 2014

#!/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
    cssfilename=`basename $sassfile`
    cssfile=$CSS_DIR/${cssfilename//sass/css}
    echo sass $sassfile $cssfile
    sass $sassfile $cssfile
    wait $!
    git add $cssfile
  done
fi

@bencaron
Copy link
Author

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