-
-
Save nixpulvis/5042764 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 |
👍 ... works straight out of the box; thanks for sharing!
GitHub appears to have changed the way raw URLs work.
Updated: Run without saving by copying one of these into your shell.
CURL: curl -Ls https://gist.github.com/nixpulvis/5042764/raw/7daa611e707f1884eb701551464bfd1dc9e7a953/gem-reset | ruby
WGET: wget -qO- https://gist.github.com/nixpulvis/5042764/raw/7daa611e707f1884eb701551464bfd1dc9e7a953/gem-reset | ruby
-:4:in split': invalid byte sequence in US-ASCII (ArgumentError) from -:4:in
Works fine, nice job, thank you!
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /Library/Ruby/Gems/2.0.0 directory.
I'm fork and fixed.
Exclude my favorite gems during gem uninstall.
If you have a gem that want to keep, it is preferable to exclude them by fork.
https://gist.github.com/zchee/d2f100f1322fd6322a44
curl -Ls https://gist.githubusercontent.com/zchee/d2f100f1322fd6322a44/raw/2b129e3136baf839d9fb530fd215800a733c1dc8/gem-reset | ruby
@nixpulvis - any ideas/suggestions for not only skipping the so-called default gems, but also the so-called bundled gems? see https://stdgems.org/ for their respective definitions.
Run without saving by copying one of these into your shell.
CURL
curl -Ls raw.github.com/gist/5042764 | rubyWGET
wget -qO- raw.github.com/gist/5042764 | ruby