diff options
| author | Adam Vandenberg | 2012-08-28 10:59:46 -0700 |
|---|---|---|
| committer | Adam Vandenberg | 2012-08-28 10:59:46 -0700 |
| commit | 99fa51692f31f34d4e197efdaa16f51bf6701d09 (patch) | |
| tree | ca2d4da2e7a08021f85bbf2833b3932743ffbefb | |
| parent | d68395724553323134bece6aaf32304ca46f5e47 (diff) | |
| download | homebrew-99fa51692f31f34d4e197efdaa16f51bf6701d09.tar.bz2 | |
Refactor brew list
| -rw-r--r-- | Library/Homebrew/cmd/list.rb | 45 |
1 files changed, 29 insertions, 16 deletions
diff --git a/Library/Homebrew/cmd/list.rb b/Library/Homebrew/cmd/list.rb index 54292f513..602396e4a 100644 --- a/Library/Homebrew/cmd/list.rb +++ b/Library/Homebrew/cmd/list.rb @@ -1,31 +1,44 @@ module Homebrew extend self def list - # Cellar doesn't until the first formula is installed. + + # Use of exec means we don't explicitly exit + list_unbrewed if ARGV.flag? '--unbrewed' + + # Unbrewed uses the PREFIX, which will exist + # Things below use the CELLAR, which doesn't until the first formula is installed. return unless HOMEBREW_CELLAR.exist? - if ARGV.flag? '--unbrewed' - dirs = HOMEBREW_PREFIX.children.select{ |pn| pn.directory? }.map{ |pn| pn.basename.to_s } - dirs -= %w[Library Cellar .git] - cd HOMEBREW_PREFIX - exec 'find', *dirs + %w[-type f ( ! -iname .ds_store ! -iname brew ! -iname brew-man.1 ! -iname brew.1 )] - elsif ARGV.flag? '--versions' - if ARGV.named.empty? - HOMEBREW_CELLAR.children.select{ |pn| pn.directory? } - else - ARGV.named.map{ |n| HOMEBREW_CELLAR+n }.select{ |pn| pn.exist? } - end.each do |d| - versions = d.children.select{ |pn| pn.directory? }.map{ |pn| pn.basename.to_s } - puts "#{d.basename} #{versions*' '}" - end + if ARGV.flag? '--versions' + list_versions elsif ARGV.named.empty? ENV['CLICOLOR'] = nil - exec 'ls', *ARGV.options_only << HOMEBREW_CELLAR if HOMEBREW_CELLAR.exist? + exec 'ls', *ARGV.options_only << HOMEBREW_CELLAR elsif ARGV.verbose? or not $stdout.tty? exec "find", *ARGV.kegs + %w[-not -type d -print] else ARGV.kegs.each{ |keg| PrettyListing.new keg } end end + +private + + def list_unbrewed + dirs = HOMEBREW_PREFIX.children.select{ |pn| pn.directory? }.map{ |pn| pn.basename.to_s } + dirs -= %w[Library Cellar .git] + cd HOMEBREW_PREFIX + exec 'find', *dirs + %w[-type f ( ! -iname .ds_store ! -iname brew ! -iname brew-man.1 ! -iname brew.1 )] + end + + def list_versions + if ARGV.named.empty? + HOMEBREW_CELLAR.children.select{ |pn| pn.directory? } + else + ARGV.named.map{ |n| HOMEBREW_CELLAR+n }.select{ |pn| pn.exist? } + end.each do |d| + versions = d.children.select{ |pn| pn.directory? }.map{ |pn| pn.basename.to_s } + puts "#{d.basename} #{versions*' '}" + end + end end class PrettyListing |
