Skip to content

Instantly share code, notes, and snippets.

@rottenbytes
Created August 29, 2012 11:54
Show Gist options
  • Save rottenbytes/3511456 to your computer and use it in GitHub Desktop.
Save rottenbytes/3511456 to your computer and use it in GitHub Desktop.
Hook chef to your vim
def test(cb_name)
result=%x[knife cookbook test #{cb_name}]
if $? != 0 then
VIM::message("Testing cookbook '#{cb_name}' failed")
else
VIM::message("Cookbook '#{cb_name}' is OK.")
end
end
def upload(name)
result=%x[knife cookbook upload #{name}]
if $? != 0 then
VIM::message("Uploading cookbook '#{name}' failed")
else
VIM::message("Upload of cookbook '#{name}' is OK.")
end
end
require 'chef'
if (ENV['HOME'] && File.exist?(File.join(ENV['HOME'], '.chef', 'knife.rb')))
Chef::Config.from_file(File.join(ENV['HOME'], '.chef', 'knife.rb'))
end
filename = VIM::Buffer.current.name()
cb_path = Chef::Config.cookbook_path[0]
cb_name = filename.gsub(cb_path+"/","").split('/')[0]
action=VIM::evaluate("g:chef_action")
actions = ["test", "upload"]
unless actions.include?(action)
VIM::message("Unknown action #{action}")
end
Object.send(action, cb_name)
function! ChefUpload()
:let g:chef_action = "upload"
:rubyfile ~/.vim/chef.rb
endfunction
function! ChefTest()
:let g:chef_action = "test"
:rubyfile ~/.vim/chef.rb
endfunction
map <c-t> :call ChefTest()<CR>
map <c-u> :call ChefUpload()<CR>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment