Skip to content

Instantly share code, notes, and snippets.

@balexand
Forked from nixpulvis/gem-reset
Last active December 14, 2015 07:49
Show Gist options
  • Save balexand/5053194 to your computer and use it in GitHub Desktop.
Save balexand/5053194 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# Remove all gems EXCEPT defaults :)
`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
@balexand
Copy link
Author

curl -Ls https://gist.github.com/balexand/5053194/raw/7daa611e707f1884eb701551464bfd1dc9e7a953/gem-reset | ruby

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment