Skip to content

Instantly share code, notes, and snippets.

@hotoo
Forked from othree/gist:182971
Created June 27, 2010 16:42
Show Gist options
  • Save hotoo/455009 to your computer and use it in GitHub Desktop.
Save hotoo/455009 to your computer and use it in GitHub Desktop.
function Js_css_compress ()
let cwd = expand('<afile>:p:h')
let nam = expand('<afile>:t:r')
let ext = expand('<afile>:e')
if -1 == match(nam, "[\._]src$")
let minfname = nam.".min.".ext
else
let minfname = substitute(nam, "[\._\-]src$", "", "g").".".ext
endif
if ext == 'less'
if executable('lessc')
cal system( 'lessc '.cwd.'/'.nam.'.'.ext.' &')
endif
else
if filewritable(cwd.'/'.minfname)
if ext == 'js' && executable('closure-compiler')
cal system( 'closure-compiler --js '.cwd.'/'.nam.'.'.ext.' > '.cwd.'/'.minfname.' &')
elseif executable('yuicompressor')
cal system( 'yuicompressor '.cwd.'/'.nam.'.'.ext.' > '.cwd.'/'.minfname.' &')
endif
endif
endif
endfunction
autocmd FileWritePost,BufWritePost *.js :call Js_css_compress()
autocmd FileWritePost,BufWritePost *.css :call Js_css_compress()
autocmd FileWritePost,BufWritePost *.less :call Js_css_compress()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment