diff options
| author | Misty De Meo | 2014-06-20 12:09:28 -0700 |
|---|---|---|
| committer | Misty De Meo | 2014-06-20 12:09:39 -0700 |
| commit | e19de9231fa2e284cc17ab753552954997060037 (patch) | |
| tree | 08064c85bd816f660415ed266a61aa9efc165277 /Library | |
| parent | 3337d7d64ae1ec7725a971ee3944e2711e14e614 (diff) | |
| download | homebrew-e19de9231fa2e284cc17ab753552954997060037.tar.bz2 | |
Revert "Removew brew-which"
This reverts commit c0a32c81eb1b176448cd41866f2d22427c729522.
Will add a deprecation notice and remove at a later point in time.
Diffstat (limited to 'Library')
| -rwxr-xr-x | Library/Contributions/cmd/brew-which.rb | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/Library/Contributions/cmd/brew-which.rb b/Library/Contributions/cmd/brew-which.rb new file mode 100755 index 000000000..870ff67a5 --- /dev/null +++ b/Library/Contributions/cmd/brew-which.rb @@ -0,0 +1,44 @@ +require 'extend/pathname' + +module Homebrew + def which_versions which_brews=nil + brew_links = Array.new + version_map = Hash.new + + real_cellar = HOMEBREW_CELLAR.realpath + + (HOMEBREW_PREFIX/'opt').subdirs.each do |path| + next unless path.symlink? && path.resolved_path_exists? + brew_links << Pathname.new(path.realpath) + 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 |
