Refactor brew list
This commit is contained in:
parent
516041dba8
commit
c1220975b9
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user