Skip to content

Instantly share code, notes, and snippets.

@acdha
Created January 16, 2013 21:08
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save acdha/4550977 to your computer and use it in GitHub Desktop.
Save acdha/4550977 to your computer and use it in GitHub Desktop.
Bulk-convert CSS to SASS SCSS using css2sass, curl and xmlstarlet
#!/bin/bash
for f in *.css; do
echo $f ${f/.css/.scss};
curl -s -X POST http://css2sass.heroku.com/xml --data-urlencode "page[css]@$f" -d commit="Convert 2 SCSS" | xmlstarlet sel -t -v /page/sass | xmlstarlet unesc > ${f/.css/.scss};
done
@voku
Copy link

voku commented Jun 5, 2014

only for info: there is also a command for this ->

sass-convert --from css --to sass foo.css bar.sass

@agronick
Copy link

This doesn't seem to work anymore. The html isn't well formed which breaks xmlstarlet and it uses a different URL. Here is a modified version that works with pearl instead of xmlstarlet. If you want scss change all the sass parts to scss.

#!/bin/bash
 
for f in *.css; do
    echo $f ${f/.css/.sass};
     curl -s -X POST http://css2sass.herokuapp.com --data-urlencode "page[css]@$f" -d commit="Convert 2 SASS"  | sed -n "s:.*<textarea id='page_sass' name='page\[sass\]'>\(.*\)</textarea>.*:\1:p" | perl -MHTML::Entities -pe 'decode_entities($_);' > ${f/.css/.sass}; 
done

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