aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
authorWil Moore III2014-05-13 12:00:32 -0600
committerAdam Vandenberg2014-05-13 11:02:48 -0700
commita04a6a399a7845f4342fd23f1765f877cdf403be (patch)
treed9b7cbbe6b0a852e97012da227fcd170412d1514 /Library
parentc03483b6a8f32e37ea59396327f29b737f4d266a (diff)
downloadbrew-a04a6a399a7845f4342fd23f1765f877cdf403be.tar.bz2
add brew-bundle-dir contributed command
Closes Homebrew/homebrew#27258. Signed-off-by: Adam Vandenberg <flangy@gmail.com>
Diffstat (limited to 'Library')
-rwxr-xr-xLibrary/Contributions/cmd/brew-bundle-dir.rb80
1 files changed, 80 insertions, 0 deletions
diff --git a/Library/Contributions/cmd/brew-bundle-dir.rb b/Library/Contributions/cmd/brew-bundle-dir.rb
new file mode 100755
index 000000000..80d662cd7
--- /dev/null
+++ b/Library/Contributions/cmd/brew-bundle-dir.rb
@@ -0,0 +1,80 @@
+#!/usr/bin/env ruby
+
+# program name.
+NAME = "bundle-dir"
+
+# defaults.
+PREFIX_DEFAULT = "~/.brews.d"
+
+# effective prefix directory.
+PREFIX = File.expand_path(ENV["BUNDLE_DIR"] || PREFIX_DEFAULT)
+
+# validate prefix directory exists and is readable.
+odie "'#{PREFIX}' does not exist, is not a directory, or is not readable." unless File.readable?(PREFIX) && File.directory?(PREFIX)
+
+# list all available brewfiles in PREFIX.
+def list
+ Dir["#{PREFIX}/**/*.brewfile"].select do |brewfile|
+ File.readable?(brewfile)
+ end
+end
+
+# edit/open all available brewfiles in PREFIX.
+def edit
+ odie "environment variable EDITOR is not set." unless ENV["EDITOR"].length > 0
+ system "$EDITOR #{list().join(' ')}"
+end
+
+# count number of `brew * install` lines across all found brewfiles.
+def count
+ system "echo #{list().join(' ')} | xargs cat | grep -vE '^[#]' | grep -vE '^$' | wc -l | awk '{ print $NR }'"
+end
+
+# print a usage message.
+def usage
+ <<-USAGE
+Usage: brew #{NAME}
+
+ Options:
+
+ -c, --count Count of formula found in all brewfiles found in PREFIX.
+ -e, --edit Edit/open all brewfiles found in PREFIX.
+ -l, --list List all brewfiles found in PREFIX.
+ -h, --help Display help information.
+ USAGE
+end
+
+# command.
+command = ARGV.first
+
+# help.
+if ["--help", "-h"].include? command
+ puts usage ; exit 0
+end
+
+# list.
+if ["--list", "-l"].include? command
+ puts list ; exit 0
+end
+
+# edit.
+if ["--edit", "-e"].include? command
+ edit ; exit 0
+end
+
+# count.
+if ["--count", "-c"].include? command
+ count ; exit 0
+end
+
+# unknown option.
+if !command.nil? && command.length > 0
+ puts "#{usage}"
+ puts "\n"
+ odie "Unknown option: #{command}"
+end
+
+# main.
+list().each do |brewfile|
+ system "brew bundle #{brewfile}"
+end