Skip to content

Instantly share code, notes, and snippets.

@remcoder
Created July 24, 2011 13:06
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save remcoder/1102600 to your computer and use it in GitHub Desktop.
Save remcoder/1102600 to your computer and use it in GitHub Desktop.
Compile LESS to CSS automatically whenever a file is modified
#!/usr/bin/env python
# determines filename and extension, then delegates compiling the LESS files to lessc via a shell command
import sys, os.path
from subprocess import call
src = sys.argv[1]
base,ext = os.path.splitext(src)
dest = base + ".css"
cmd = "lessc %s > %s" % (src , dest)
#print cmd
print "%s -> %s" % (os.path.split(src)[1], os.path.split(dest)[1])
call( cmd , shell=True)
#!/bin/bash
# Compile LESS to CSS automatically whenever a file is modified
# requirements
#
# 1 the LESS compiler (lessc)
# - first you need Node.js, download it at http://nodejs.org/
# - then install npm from http://npmjs.org/
# - then install LESS:
#
# $ npm install less
#
# 2 Watchdog
# - requires Python
# - install via easy_install:
#
# $ sudo easy_install Watchdog
#
# NOTE: we'll be using the 'watchmedo' script included with Watchdog
#
# 3 make sure both 'watchmedo' and 'lessc' are in your PATH
#
# 4 from the directory containing your LESS file, run this command:
#
# $ ./watch_less.sh
#
echo "Watching folder `pwd`"
watchmedo shell-command --patterns="*.less" --command='./build_less.py ${watch_src_path} ' .
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment