Skip to content

Instantly share code, notes, and snippets.

@mAu888
Created March 11, 2012 15:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mAu888/2016822 to your computer and use it in GitHub Desktop.
Save mAu888/2016822 to your computer and use it in GitHub Desktop.
Autocompile plugin for Sublime Text 2
import sublime, sublime_plugin, commands, os
class LESSCompileOnSave(sublime_plugin.EventListener):
def on_post_save(self, view):
path = os.environ["PATH"]
if(path.find('/usr/local/bin') == -1):
os.environ["PATH"] = path + ':/usr/local/bin'
file_name = os.path.basename(view.file_name())
base_name = os.path.splitext(file_name)[0]
ext = os.path.splitext(file_name)[1]
path = os.path.dirname(view.file_name())
less_path = os.path.realpath(path + '/../../css')
coffee_path = os.path.realpath(path + '/../../js')
if(ext == '.less' and os.path.isdir(less_path)):
commands.getstatusoutput('/usr/local/bin/lessc -x ' + view.file_name() + ' ' + less_path + '/' + base_name + '.css')
elif(ext == '.coffee' and os.path.isdir(coffee_path)):
commands.getstatusoutput('/usr/local/bin/coffee -o ' + coffee_path + ' -c ' + view.file_name())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment