Skip to content

Instantly share code, notes, and snippets.

@dunckr
Last active April 7, 2016 10:44
Show Gist options
  • Save dunckr/1e149d5decf1f02e4fb9 to your computer and use it in GitHub Desktop.
Save dunckr/1e149d5decf1f02e4fb9 to your computer and use it in GitHub Desktop.
less2sass multiple files https://rubygems.org/gems/less2sass
for filename in ./*.less; do less2sass "${filename}" "_${filename/.less/.scss}"; done
@jnaklaas
Copy link

jnaklaas commented Apr 7, 2016

I had errors using the script, caused by the underscore - the script tries to create files in _./filename.scss instead of ./_filename.scss.
Removing the ./ solves the errors.

I enhanced the script a bit so you can give optional parameters for less/source and sass/destination directories:

# script by github.com/jnaklaas
# base script by github.com/dunckr: https://gist.github.com/dunckr/1e149d5decf1f02e4fb9
LESS_PATH=${1:-"./"}
SASS_PATH=${2:-$LESS_PATH}
mkdir -p $SASS_PATH

for filename in $LESS_PATH*.less; do
    DESTINATION=$SASS_PATH"_`basename $filename .less`.scss"
    echo "less2sass $filename to $DESTINATION"
    less2sass "${filename}" $DESTINATION; 
done

Execute like this:

$ sh less2sass.sh less/ sass/

If you need your sass files in the same folder:

$ sh less2sass.sh less/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment