Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@grncdr
Created February 13, 2016 09:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grncdr/a9f36c06ee852da0f9d8 to your computer and use it in GitHub Desktop.
Save grncdr/a9f36c06ee852da0f9d8 to your computer and use it in GitHub Desktop.
Script for cleaning up old homebrew deps
#!/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