aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
authorMike McQuaid2014-09-20 15:10:36 +0100
committerMike McQuaid2014-09-24 15:22:59 -0700
commit86ded7833cdc4309038d1192b430cbb2d782f9b4 (patch)
tree8fc543dae3a36571e5789519aebf2a1072183fdf /Library
parent3b8a6c072426922946e74619f8eef511d6c35c34 (diff)
downloadbrew-86ded7833cdc4309038d1192b430cbb2d782f9b4.tar.bz2
brew-cleanup-installed: Rubify, make internal cmd.
Diffstat (limited to 'Library')
-rwxr-xr-xLibrary/Contributions/cmd/brew-cleanup-installed22
-rwxr-xr-xLibrary/Homebrew/cmd/cleanup-installed.rb20
2 files changed, 20 insertions, 22 deletions
diff --git a/Library/Contributions/cmd/brew-cleanup-installed b/Library/Contributions/cmd/brew-cleanup-installed
deleted file mode 100755
index 9ce9ccbe5..000000000
--- a/Library/Contributions/cmd/brew-cleanup-installed
+++ /dev/null
@@ -1,22 +0,0 @@
-#!/bin/sh
-# brew-cleanup-installed: uninstall all non-whitelisted Homebrew formulae.
-#
-# Useful for maintainers/testers who regularly install lots of formulae
-# they don't actually use.
-#
-# 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
-
-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
diff --git a/Library/Homebrew/cmd/cleanup-installed.rb b/Library/Homebrew/cmd/cleanup-installed.rb
new file mode 100755
index 000000000..b79a380c1
--- /dev/null
+++ b/Library/Homebrew/cmd/cleanup-installed.rb
@@ -0,0 +1,20 @@
+# brew-cleanup-installed: uninstall all non-whitelisted Homebrew formulae.
+#
+# Useful for maintainers/testers who regularly install lots of formulae
+# they don't actually use.
+#
+# Populate ~/.brew-cleanup-installed with the formulae you want to keep
+# installed. All others will be uninstalled when brew-cleanup-installed is run.
+
+module Homebrew
+ def cleanup_installed
+ cleanup_file = Pathname.new "#{ENV["HOME"]}/.brew-cleanup-installed"
+ return unless cleanup_file.exist?
+
+ 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