Skip to content

Instantly share code, notes, and snippets.

@shoaibali
Created May 7, 2016 12:03
Show Gist options
  • Save shoaibali/6fe73e5ce7cf02c75b690b203018cf22 to your computer and use it in GitHub Desktop.
Save shoaibali/6fe73e5ce7cf02c75b690b203018cf22 to your computer and use it in GitHub Desktop.
convert gem list to gem install reference: https://www.krzywanski.net/archives/451
#!/usr/bin/perl -w
# We're strict
use strict;
# Get list of installed gems
my @gems = qx(gem list);
chomp(@gems);
# Create commands
foreach my $gem (@gems)
{
# Match gem and versions
$gem =~ m/(\S+)\s\((.+)\)/i;
# Gem name
$gem = $1;
# Save them into array
my @gem_versions = split(/,/, $2);
# Print out commands
foreach (@gem_versions)
{
# Remove all whitespaces
$_ =~ s/^\s+//;
print "gem install $gem --version=$_\n";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment