diff options
| author | Mike McQuaid | 2012-03-18 15:33:21 +1300 |
|---|---|---|
| committer | Mike McQuaid | 2012-03-18 15:34:41 +1300 |
| commit | e33937a1e35e75dffae043f22e975bfd51dea409 (patch) | |
| tree | 0c04edf7d597577808d5dc72a68718e047052168 /Library/Contributions/cmds/brew-which.rb | |
| parent | d47cf55f68fb1d381cfbdc9de905dc33c7ce5a83 (diff) | |
| download | brew-e33937a1e35e75dffae043f22e975bfd51dea409.tar.bz2 | |
Rename external commands directory from examples.
Fixes Homebrew/homebrew#10829.
Diffstat (limited to 'Library/Contributions/cmds/brew-which.rb')
| -rwxr-xr-x | Library/Contributions/cmds/brew-which.rb | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/Library/Contributions/cmds/brew-which.rb b/Library/Contributions/cmds/brew-which.rb new file mode 100755 index 000000000..b3318ee76 --- /dev/null +++ b/Library/Contributions/cmds/brew-which.rb @@ -0,0 +1,49 @@ +require 'extend/pathname' + + +module Homebrew extend self + def which_versions which_brews=nil + brew_links = Array.new + version_map = Hash.new + + real_cellar = HOMEBREW_CELLAR.realpath + + paths=%w[bin sbin lib].collect {|d| HOMEBREW_PREFIX+d} + + paths.each do |path| + path.find do |path| + next unless path.symlink? && path.resolved_path_exists? + brew_links << Pathname.new(path.realpath) + end + end + + brew_links = brew_links.collect{|p|p.relative_path_from(real_cellar).to_s}.reject{|p|p.start_with?("../")} + + 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 + + next unless which_brews.include? brew if which_brews + + versions = version_map[brew] || [] + versions << version unless versions.include? version + version_map[brew] = versions + end + + return version_map + end + + def which + which_brews = ARGV.named.empty? ? nil : ARGV.named + + brews = which_versions which_brews + brews.keys.sort.each do |b| + puts "#{b}: #{brews[b].sort*' '}" + end + puts + end +end + +Homebrew.which |
