2010-06-14 11:48:06 -07:00
|
|
|
require 'extend/pathname'
|
|
|
|
|
|
|
|
|
2011-06-13 10:26:20 -07:00
|
|
|
module Homebrew extend self
|
|
|
|
def which_versions which_brews=nil
|
|
|
|
brew_links = Array.new
|
|
|
|
version_map = Hash.new
|
|
|
|
|
|
|
|
real_cellar = HOMEBREW_CELLAR.realpath
|
|
|
|
|
2011-06-19 22:12:44 -07:00
|
|
|
paths=%w[bin sbin lib].collect {|d| HOMEBREW_PREFIX+d}
|
2011-06-13 10:26:20 -07:00
|
|
|
|
|
|
|
paths.each do |path|
|
|
|
|
path.find do |path|
|
|
|
|
next unless path.symlink? && path.resolved_path_exists?
|
|
|
|
brew_links << Pathname.new(path.realpath)
|
|
|
|
end
|
|
|
|
end
|
2010-06-14 11:48:06 -07:00
|
|
|
|
2011-06-13 10:26:20 -07:00
|
|
|
brew_links = brew_links.collect{|p|p.relative_path_from(real_cellar).to_s}.reject{|p|p.start_with?("../")}
|
2010-06-14 11:48:06 -07:00
|
|
|
|
2011-06-13 10:26:20 -07:00
|
|
|
brew_links.each do |p|
|
|
|
|
parts = p.split("/")
|
|
|
|
next if parts.count < 2 # Shouldn't happen for normally installed brews
|
|
|
|
brew = parts.shift
|
|
|
|
version = parts.shift
|
2010-06-14 11:48:06 -07:00
|
|
|
|
2011-06-13 10:26:20 -07:00
|
|
|
next unless which_brews.include? brew if which_brews
|
2010-06-14 11:48:06 -07:00
|
|
|
|
2011-06-13 10:26:20 -07:00
|
|
|
versions = version_map[brew] || []
|
|
|
|
versions << version unless versions.include? version
|
|
|
|
version_map[brew] = versions
|
2010-06-14 11:48:06 -07:00
|
|
|
end
|
2011-06-13 10:26:20 -07:00
|
|
|
|
|
|
|
return version_map
|
2010-06-14 11:48:06 -07:00
|
|
|
end
|
|
|
|
|
2011-06-13 10:26:20 -07:00
|
|
|
def which
|
|
|
|
which_brews = ARGV.named.empty? ? nil : ARGV.named
|
2010-06-14 11:48:06 -07:00
|
|
|
|
2011-06-13 10:26:20 -07:00
|
|
|
brews = which_versions which_brews
|
|
|
|
brews.keys.sort.each do |b|
|
|
|
|
puts "#{b}: #{brews[b].sort*' '}"
|
|
|
|
end
|
|
|
|
puts
|
2010-06-14 11:48:06 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-06-13 10:26:20 -07:00
|
|
|
Homebrew.which
|