Skip to content

Instantly share code, notes, and snippets.

@BBB
Created August 30, 2011 12:36
Show Gist options
  • Save BBB/1180798 to your computer and use it in GitHub Desktop.
Save BBB/1180798 to your computer and use it in GitHub Desktop.
import sublime, sublime_plugin, subprocess, os
class CompileLessOnSave(sublime_plugin.EventListener):
def on_post_save(self, view):
if not view.file_name().endswith('.less'):
return
if os.name == "nt":
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
folder_name, file_name = os.path.split(view.file_name())
args = ['lessc', '-m', view.file_name()]
print('Minifying: ' + view.file_name())
print(' '.join(args)) # lessc -m C:\lesstest\hello.less
view.window().run_command('exec', {'cmd': args, 'working_dir': folder_name})
process = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, startupinfo=startupinfo)
print('Compiled ' + view.file_name())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment