Skip to content

Instantly share code, notes, and snippets.

@tacahiroy
Created May 28, 2012 16:59
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tacahiroy/2820089 to your computer and use it in GitHub Desktop.
Save tacahiroy/2820089 to your computer and use it in GitHub Desktop.
upload current editing Chef cookbook
if executable('knife')
function! s:upload_cookbook(...) abort
let path = expand('%:p')
if path !~# '/cookbooks/[^/]\+/.\+'
return
endif
let cookbooks = [get(a:, 1, '')]
let m = matchlist(path, '^\(.\+/cookbooks/[^/]\+\)/\([^/]\+\)/')
let cb_path = m[1]
if index(cookbooks, m[2]) == -1
call insert(cookbooks, m[2])
endif
if 0 < len(cookbooks)
let cookbooks = filter(cookbooks, 'isdirectory(cb_path."/".v:val)')
let mes = 'Uploading cookbook' . (1 < len(cookbooks) ? 's' : '')
let cmd = printf('knife cookbook upload -o %s %s;', cb_path, join(cookbooks, ' '))
if s:is_mac && executable('growlnotify')
let gtitle = 'cookbook upload: ' . join(cookbooks, ' ')
let gapp = 'Chef'
let cmd .= 'if [ $? -eq 0 ]; then echo SUCCESS; else echo FAILURE; fi | '
let cmd .= printf('growlnotify -n %s \"%s\"', gapp, gtitle)
endif
echomsg printf('%s: %s', mes, join(cookbooks, ' '))
execute ':!' . cmd
" call s:tmux.run(cmd, 1, 1)
else
echoerr 'no cookbooks are found.'
endif
endfunction
command! -nargs=* CCookbookUpload call s:upload_cookbook(<f-args>)
nnoremap <Space>U :<C-u>CCookbookUpload<Cr>
endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment