Skip to content

Instantly share code, notes, and snippets.

@pierswarmers
Created September 4, 2012 04:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pierswarmers/3616565 to your computer and use it in GitHub Desktop.
Save pierswarmers/3616565 to your computer and use it in GitHub Desktop.
Script to run watchr and compile LESS
#!/bin/bash
# These are the original commands, courtesy of:
# http://www.ravelrumba.com/blog/watch-compile-less-command-line/
# Requires watchr: https://github.com/mynyml/watchr
# watchr -e 'watch(".*\.less$") { |f| system("lessc #{f[0]} > #{f[0]}.css && echo \"#{f[0]} > #{f[0]}.css\" "}') }
# Requires inotify-tools: https://github.com/rvoicilas/inotify-tools
# while true;do N=`find -name "*.less" `;inotifywait -qe modify $N ;for f in $N;do lessc $f ${f%.*}.css;done;done
# I wanted to add something like this:
# ls *.less.css | awk -F. '{ print "mv "$1".less.css "$1 ".css" }' | bash
# I was having trouble mixing Bash and Ruby, so I settled on doing this:
# less_watcher:
watchr -e 'watch(".*\.less$") { |f| system("echo \"#{f[0]} > #{f[0]}.css\" && less_helper.sh #{f[0]}") }'
# less_helper.sh:
lessc $1 > $1.css
echo $1 | awk -F. '{ print "mv "$1".less.css "$1 ".css" }' | bash
# I guess I could've replaced the awk one-liner with a Ruby one liner,
# especially since my command now needs to be run within the directory it's
# watching. when I need to monitor multiple directories I'll change it.
# For more info: http://tommyseven.blogspot.com/2012/04/automatically-compile-less.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment