Created
February 13, 2016 09:55
-
-
Save grncdr/a9f36c06ee852da0f9d8 to your computer and use it in GitHub Desktop.
Script for cleaning up old homebrew deps
This file contains hidden or 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 perl | |
use strict; | |
sub main { | |
my $keep = {}; | |
loop($keep); | |
} | |
sub loop { | |
my $keep = shift; | |
my $leafSet = {}; | |
foreach (`brew leaves`) { | |
chomp; | |
next if $keep->{$_}; | |
$leafSet->{$_} = 1; | |
} | |
my @leaves = sort(keys $leafSet); | |
return unless scalar @leaves; | |
foreach my $leaf (@leaves) { | |
print "\n\n====> "; | |
system ("brew", "info", $leaf); | |
while (1) { | |
print "Would you like to keep $leaf? [Y/n]: "; | |
my $yn = readline; | |
chomp $yn; | |
if ($yn eq "y" or $yn eq "") { | |
$keep->{$leaf} = 1; | |
last; | |
} elsif ($yn eq "n") { | |
system("brew", "uninstall", $leaf); | |
last; | |
} | |
} | |
} | |
loop($keep); | |
} | |
main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment