2013-11-11 14:07:18 +00:00
|
|
|
# brew-bundle.rb
|
2013-11-16 17:39:20 -06:00
|
|
|
#
|
|
|
|
# Usage: brew bundle [path]
|
|
|
|
#
|
|
|
|
# Looks for a Brewfile and runs each line as a brew command.
|
|
|
|
#
|
2013-11-17 09:41:41 +00:00
|
|
|
# brew bundle # Looks for "./Brewfile"
|
2013-11-18 15:46:34 -07:00
|
|
|
# brew bundle path/to/dir # Looks for "path/to/dir/Brewfile"
|
|
|
|
# brew bundle path/to/file # Looks for "path/to/file"
|
2013-11-10 16:27:36 -06:00
|
|
|
#
|
2013-11-11 14:07:18 +00:00
|
|
|
# For example, given a Brewfile with the following contents:
|
2013-11-10 16:27:36 -06:00
|
|
|
# tap foo/bar
|
|
|
|
# install spark
|
|
|
|
#
|
2013-11-11 14:07:18 +00:00
|
|
|
# Running `brew bundle` will run the commands `brew tap foo/bar`
|
|
|
|
# and `brew install spark`.
|
|
|
|
|
2013-11-17 09:41:41 +00:00
|
|
|
path = 'Brewfile'
|
|
|
|
error = ' in current directory'
|
|
|
|
|
|
|
|
if ARGV.first
|
|
|
|
if File.directory? ARGV.first
|
|
|
|
path = "#{ARGV.first}/#{path}"
|
|
|
|
error = " in '#{ARGV.first}'"
|
|
|
|
else
|
|
|
|
path = ARGV.first
|
|
|
|
error = " at '#{ARGV.first}'"
|
|
|
|
end
|
2013-11-16 17:39:20 -06:00
|
|
|
end
|
|
|
|
|
2013-11-17 09:41:41 +00:00
|
|
|
raise "Cannot find Brewfile#{error}" unless File.exist? path
|
2013-11-10 16:27:36 -06:00
|
|
|
|
2013-12-07 23:36:44 -07:00
|
|
|
File.readlines(path).each_with_index do |line, index|
|
2013-11-11 14:07:18 +00:00
|
|
|
command = line.chomp
|
|
|
|
next if command.empty?
|
|
|
|
next if command.chars.first == '#'
|
|
|
|
|
2013-12-07 23:36:44 -07:00
|
|
|
brew_cmd = "brew #{command}"
|
|
|
|
odie "Command failed: L#{index+1}:#{brew_cmd}" unless system brew_cmd
|
2013-11-10 16:27:36 -06:00
|
|
|
end
|