Skip to content

Instantly share code, notes, and snippets.

@capoferro
Created April 3, 2012 22:55
Show Gist options
  • Save capoferro/2296122 to your computer and use it in GitHub Desktop.
Save capoferro/2296122 to your computer and use it in GitHub Desktop.
ruby_block 'set P4CONFIG in shell rc file' do
block do
content = nil
File.open(shellrc_path, 'r') do |file|
content = file.read
p4config_matcher = 'P4CONFIG=\"[^\"]*\"'
content.gsub! /^.*#{p4config_matcher}.*$/, set_p4config_line
content << "\n\n#{set_p4config_line}" unless content =~ /#{p4config_matcher}/
end
File.open(shellrc_path, 'w') do |f|
f.print(content)
end
end
not_if do
begin
File.open(shellrc_path) do |file|
!!(file.readlines.join("\n") =~ /#{set_p4config_line}/)
end
rescue Errno::ENOENT
false
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment