Created
August 29, 2012 11:54
-
-
Save rottenbytes/3511456 to your computer and use it in GitHub Desktop.
Hook chef to your vim
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
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) |
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
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