Created
May 28, 2012 16:59
-
-
Save tacahiroy/2820089 to your computer and use it in GitHub Desktop.
upload current editing Chef cookbook
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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