Skip to content

Instantly share code, notes, and snippets.

@joshmcarthur
Created November 3, 2011 03:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshmcarthur/1335721 to your computer and use it in GitHub Desktop.
Save joshmcarthur/1335721 to your computer and use it in GitHub Desktop.
A simple Ruby script to make a shell command that can be executed to install the gems *you* have installed in *their* environment
#!/usr/bin/env ruby
### gem_to_command.rb ###############################################################
# Produce a command to install the gems you currently have installed (using gem list)
# Makes a simple Shell script that can be run on Linux or Mac OS X
#
# Author: @sudojosh
######################################################################################
gems = `gem list`
File.open("install_gems.sh", "wb") do |script|
script << "#!/usr/bin/env ruby\n"
gems = gems.split("\n").map { |gem|
gem = gem.split(' ').map { |part|
part.gsub(/[^\w\.\-]/, '')
};
[gem[0], gem[1..-1].min]
}
gems.each { |gem|
script << "gem install #{gem[0]} -v=#{gem[1]}"
script << " && " unless gem[0] == gems.last[0]
}
end
puts "Wrote install_gems.sh"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment