Created
January 22, 2018 18:29
-
-
Save S1SYPHOS/dadd75a1c1fc9d253b9a643f69752e03 to your computer and use it in GitHub Desktop.
This script removes all ruby gems except default ones.
This file contains 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/env ruby | |
`gem list -d`.split(/\n\n^(?=\w)/).each do |data| | |
match = data.match(/(?<name>([^\s]+)) \((?<versions>.*)\)/) | |
name = match[:name] | |
versions = match[:versions].split(', ') | |
if match = data.match(/^.*\(([\d\.]*),? ?default\): .*$/) | |
next if match[1].empty? # it's the only version if this match is empty | |
versions.delete(match[1] || versions[0]) | |
end | |
versions.each { |v| system "gem uninstall -Ix #{name} -v #{v}" } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment