Skip to content

Instantly share code, notes, and snippets.

@olauzon
Created October 12, 2010 22:36
Show Gist options
  • Save olauzon/623051 to your computer and use it in GitHub Desktop.
Save olauzon/623051 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# Place this script in your shell's load path
require 'rubygems'
begin
require 'highline/import'
rescue
puts "'sudo gem install highline' in your system Ruby"
end
# Generate .rvmrc file in a project directory
file_name = '.rvmrc'
def project_path
@project_path ||= Dir.pwd.split('/').last.strip
end
def project
@project ||= ARGV[1] || [project_path, Time.now.to_i].join('-')
end
def ruby
@ruby ||= ARGV[0] || 'ruby-1.8.7-p174'
end
def rubies
@rubies ||= `rvm list`.split("\n").
map(&:strip).
select(&:any?).
compact.
reject {|s| s == 'rvm rubies'}.
map {|s| s.split('[').first.strip }
end
choose do |menu|
menu.prompt = 'Choose a Ruby'
rubies.each do |r|
menu.choice(r) do
@ruby = r
say("You selected Ruby: #{ruby}")
end
end
end
puts ''
@project = ask("Input a name for your project's gemset: ") do |q|
q.default = project
end
puts ''
gemset = "#{ruby}@#{project}"
create_gemset = "rvm --create use #{gemset}"
gemsource = 'source :rubygems'
File.open('Gemfile', 'w') { |f| f.write(gemsource) } unless File.exists?('Gemfile')
puts "Creating #{gemset} gemset..."
puts ''
File.open(file_name, 'w') { |f| f.write(create_gemset) }
system [create_gemset,
'rvm rvmrc trust',
"rvm #{gemset} gem install bundler --no-ri --no-rdoc"].
join(' && ')
puts ''
puts ".rvmrc, Gemfile, and Bundler installed for #{project}"
puts "To load this gemset, run:"
puts "rvm rvmrc load"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment