Less CSS compiler on Ubuntu: How to watch dependencies and compile on save

less, ubuntu

Solution

If your less files are stored in subfolders of `less/`, you can watch for changes with inotifywait:

sudo apt-get install inotify-tools

Then create a `autocompile.sh` file:

#! /bin/bash
while inotifywait -r less/*
do
  lessc less/main.less > css/main.css # your compile command
done

Don't forget to give it execution rights:

chmod u+x autocompile.sh

And run it:

./autocompile.sh

Your compile command will be run every time a file in `less/` will be modified.

Problem

I just switched to Ubuntu (12.04) from Windows and I'm struggling to get a solution to compile my .less files just the way I used to do by using the "Winless" app. This app's beauty is that I just have to monitor a folder, save the main file... and everything that was changed in the dependent files get compiled as well. I googled for an hour and have seen many answers but none of them is straightforward. And I'm a ubuntu noob, so things are difficult to understand. The closest one is less css for ubuntu (and compilation automatically)?, but it does not work as expected at all. Can someone please point me to the right direction? I would like clear instructions about what I need to install and config in order to get a similar behavior of the "WinLess" program.

Original source