diff options
| author | Adam Vandenberg | 2010-06-14 11:48:06 -0700 |
|---|---|---|
| committer | Adam Vandenberg | 2010-07-08 22:41:51 -0700 |
| commit | 6b1a8be58e6bf903a6442dee99de373a5ae89dbd (patch) | |
| tree | d36fa25b24dfcf441bb272731a85299e2ba4f465 /Library | |
| parent | a6b6de63a999494e378ec9ce50bec85fa7a8f918 (diff) | |
| download | brew-6b1a8be58e6bf903a6442dee99de373a5ae89dbd.tar.bz2 | |
External command "brew which"
A work-in-progress command, "brew which" will show which versions of formulae
you have installed based on what symlinks exist from HOMEBREW_PREFIX back into
the Cellar.
Thus, if you happen to have symlinks into two different versions of a brew in
the Cellar (typically an error), both of those versions will be listed.
This is a diagnostic command, but some of this code will be the basis for
possible future better handling of multiple-versions-at-once.
Diffstat (limited to 'Library')
| -rwxr-xr-x | Library/Contributions/examples/brew-which.rb | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/Library/Contributions/examples/brew-which.rb b/Library/Contributions/examples/brew-which.rb new file mode 100755 index 000000000..a331e9f45 --- /dev/null +++ b/Library/Contributions/examples/brew-which.rb @@ -0,0 +1,53 @@ +require 'extend/pathname' + +REAL_CELLAR = HOMEBREW_CELLAR.realpath + +class String + def starts_with?(prefix) + prefix = prefix.to_s + self[0, prefix.length] == prefix + end +end + +class Pathname + def starts_with?(prefix) + prefix = prefix.to_s + self.to_s[0, prefix.length] == prefix + end +end + + +def audit + brew_links = Array.new + version_map = Hash.new + + # paths=%w[bin sbin etc lib include share].collect {|d| HOMEBREW_PREFIX+d} + paths=%w[bin].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.starts_with?("../")} + brew_links.each do |p| + parts = p.split("/") + next if parts.count < 2 # Shouldn't happen + brew = parts.shift + version = parts.shift + + versions = version_map[brew] || [] + versions << version unless versions.include? version + version_map[brew] = versions + end + + return version_map +end + +brews = audit +brews.keys.sort.each do |b| + puts "#{b}: #{brews[b].sort*' '}" +end +puts |
