Skip to content
Snippets Groups Projects
Commit 86ded783 authored by Mike McQuaid's avatar Mike McQuaid
Browse files

brew-cleanup-installed: Rubify, make internal cmd.

parent 3b8a6c07
No related branches found
No related tags found
No related merge requests found
#!/bin/sh
# brew-cleanup-installed: uninstall all non-whitelisted Homebrew formulae.
#
# Useful for maintainers/testers who regularly install lots of formulae
......@@ -7,16 +6,15 @@
# Populate ~/.brew-cleanup-installed with the formulae you want to keep
# installed. All others will be uninstalled when brew-cleanup-installed is run.
# Exit on any command failures
set -e
module Homebrew
def cleanup_installed
cleanup_file = Pathname.new "#{ENV["HOME"]}/.brew-cleanup-installed"
return unless cleanup_file.exist?
BREW_CLEAN_WHITELIST=~/.brew-cleanup-installed
# Do nothing and exit if the file doesn't exist.
[ -s $BREW_CLEAN_WHITELIST ]
BREW_LIST=$TMPDIR/brew-installed-list
# comm needs both lists to be sorted so ensure the dotfile is sorted first.
sort --unique ~/.brew-cleanup-installed --output ~/.brew-cleanup-installed
brew list > $BREW_LIST
comm -13 $BREW_CLEAN_WHITELIST $BREW_LIST | xargs brew uninstall
rm $BREW_LIST
kept_formulae = cleanup_file.read.lines.map(&:strip)
current_formulae = `brew list`.lines.map(&:strip)
uninstall_formulae = current_formulae - kept_formulae
return if uninstall_formulae.empty?
safe_system "brew", "uninstall", *uninstall_formulae
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment