Skip to content

Instantly share code, notes, and snippets.

@a0s
Created May 1, 2016 10:30
Show Gist options
  • Save a0s/29a58c8df6446a87c50ec035b2b5dfcd to your computer and use it in GitHub Desktop.
Save a0s/29a58c8df6446a87c50ec035b2b5dfcd to your computer and use it in GitHub Desktop.
#!ruby
# Requirements:
# brew install trash
casks_path = '/opt/homebrew-cask/Caskroom'
if `brew list | grep trash`.empty?
puts 'Please make "brew install trash" before'
exit!
end
Dir['/opt/homebrew-cask/Caskroom/*'].each do |program|
versions = Dir["#{program}/*"].map{|version| [File.ctime(version), version] }
next if versions.size == 1
versions.sort! {|a,b| a[0]<=>b[0]}
puts "#{versions.pop[1]}"
versions.reverse.each do |_, version|
`trash #{version}`
puts "#{version} trashed"
end
end
@a0s
Copy link
Author

a0s commented May 1, 2016

ruby brew-cask-cleanup2.rb

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