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.

Revisions

  1. a0s revised this gist May 1, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion brew-cask-cleanup2.rb
    Original file line number Diff line number Diff line change
    @@ -16,7 +16,7 @@
    versions.sort! {|a,b| a[0]<=>b[0]}
    puts "#{versions.pop[1]}"
    versions.reverse.each do |_, version|
    # `trash #{version}`
    `trash #{version}`
    puts "#{version} trashed"
    end
    end
  2. a0s created this gist May 1, 2016.
    22 changes: 22 additions & 0 deletions brew-cask-cleanup2.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    #!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