Refactor brew list
This commit is contained in:
parent
516041dba8
commit
c1220975b9
@ -1,14 +1,35 @@
|
|||||||
module Homebrew extend self
|
module Homebrew extend self
|
||||||
def list
|
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?
|
return unless HOMEBREW_CELLAR.exist?
|
||||||
|
|
||||||
if ARGV.flag? '--unbrewed'
|
if ARGV.flag? '--versions'
|
||||||
|
list_versions
|
||||||
|
elsif ARGV.named.empty?
|
||||||
|
ENV['CLICOLOR'] = nil
|
||||||
|
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 = HOMEBREW_PREFIX.children.select{ |pn| pn.directory? }.map{ |pn| pn.basename.to_s }
|
||||||
dirs -= %w[Library Cellar .git]
|
dirs -= %w[Library Cellar .git]
|
||||||
cd HOMEBREW_PREFIX
|
cd HOMEBREW_PREFIX
|
||||||
exec 'find', *dirs + %w[-type f ( ! -iname .ds_store ! -iname brew ! -iname brew-man.1 ! -iname brew.1 )]
|
exec 'find', *dirs + %w[-type f ( ! -iname .ds_store ! -iname brew ! -iname brew-man.1 ! -iname brew.1 )]
|
||||||
elsif ARGV.flag? '--versions'
|
end
|
||||||
|
|
||||||
|
def list_versions
|
||||||
if ARGV.named.empty?
|
if ARGV.named.empty?
|
||||||
HOMEBREW_CELLAR.children.select{ |pn| pn.directory? }
|
HOMEBREW_CELLAR.children.select{ |pn| pn.directory? }
|
||||||
else
|
else
|
||||||
@ -17,14 +38,6 @@ module Homebrew extend self
|
|||||||
versions = d.children.select{ |pn| pn.directory? }.map{ |pn| pn.basename.to_s }
|
versions = d.children.select{ |pn| pn.directory? }.map{ |pn| pn.basename.to_s }
|
||||||
puts "#{d.basename} #{versions*' '}"
|
puts "#{d.basename} #{versions*' '}"
|
||||||
end
|
end
|
||||||
elsif ARGV.named.empty?
|
|
||||||
ENV['CLICOLOR'] = nil
|
|
||||||
exec 'ls', *ARGV.options_only << HOMEBREW_CELLAR if HOMEBREW_CELLAR.exist?
|
|
||||||
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
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user