Created
May 7, 2016 12:03
-
-
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
This file contains hidden or 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
#!/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