2014-06-07 17:49:07 -05:00
|
|
|
require "metafiles"
|
2015-06-20 22:48:45 +08:00
|
|
|
require "formula"
|
2014-06-07 17:49:07 -05:00
|
|
|
|
2014-06-18 22:41:47 -05:00
|
|
|
module Homebrew
|
2010-09-11 20:22:54 +01:00
|
|
|
def list
|
2012-08-28 10:59:46 -07:00
|
|
|
# Use of exec means we don't explicitly exit
|
2015-08-03 13:09:07 +01:00
|
|
|
list_unbrewed if ARGV.flag? "--unbrewed"
|
2012-08-28 10:59:46 -07:00
|
|
|
|
|
|
|
# Unbrewed uses the PREFIX, which will exist
|
|
|
|
# Things below use the CELLAR, which doesn't until the first formula is installed.
|
2015-02-03 20:26:57 -05:00
|
|
|
unless HOMEBREW_CELLAR.exist?
|
|
|
|
raise NoSuchKegError.new(ARGV.named.first) if ARGV.named.any?
|
|
|
|
return
|
|
|
|
end
|
2012-08-28 10:52:51 -07:00
|
|
|
|
2015-08-03 13:09:07 +01:00
|
|
|
if ARGV.include?("--pinned") || ARGV.include?("--versions")
|
2014-09-06 19:12:03 -07:00
|
|
|
filtered_list
|
2010-09-11 20:22:54 +01:00
|
|
|
elsif ARGV.named.empty?
|
2015-06-20 22:48:45 +08:00
|
|
|
if ARGV.include? "--full-name"
|
|
|
|
full_names = Formula.installed.map(&:full_name).sort do |a, b|
|
|
|
|
if a.include?("/") && !b.include?("/")
|
|
|
|
1
|
|
|
|
elsif !a.include?("/") && b.include?("/")
|
|
|
|
-1
|
|
|
|
else
|
|
|
|
a <=> b
|
|
|
|
end
|
|
|
|
end
|
|
|
|
puts_columns full_names
|
|
|
|
else
|
2015-08-03 13:09:07 +01:00
|
|
|
ENV["CLICOLOR"] = nil
|
|
|
|
exec "ls", *ARGV.options_only << HOMEBREW_CELLAR
|
2015-06-20 22:48:45 +08:00
|
|
|
end
|
2015-08-03 13:09:07 +01:00
|
|
|
elsif ARGV.verbose? || !$stdout.tty?
|
2014-06-26 14:08:17 -05:00
|
|
|
exec "find", *ARGV.kegs.map(&:to_s) + %w[-not -type d -print]
|
2010-09-11 20:22:54 +01:00
|
|
|
else
|
2015-08-03 13:09:07 +01:00
|
|
|
ARGV.kegs.each { |keg| PrettyListing.new keg }
|
2010-09-11 20:22:54 +01:00
|
|
|
end
|
|
|
|
end
|
2012-08-28 10:59:46 -07:00
|
|
|
|
2013-04-07 00:49:56 -05:00
|
|
|
private
|
2012-08-28 10:59:46 -07:00
|
|
|
|
2013-07-31 15:18:37 -05:00
|
|
|
UNBREWED_EXCLUDE_FILES = %w[.DS_Store]
|
|
|
|
UNBREWED_EXCLUDE_PATHS = %w[
|
|
|
|
bin/brew
|
|
|
|
lib/gdk-pixbuf-2.0/*
|
|
|
|
lib/gio/*
|
|
|
|
lib/node_modules/*
|
|
|
|
lib/python[23].[0-9]/*
|
2015-04-06 03:41:24 +01:00
|
|
|
lib/pypy/*
|
|
|
|
lib/pypy3/*
|
|
|
|
share/pypy/*
|
|
|
|
share/pypy3/*
|
2014-11-11 11:38:16 -06:00
|
|
|
share/doc/homebrew/*
|
2013-07-31 15:18:37 -05:00
|
|
|
share/info/dir
|
|
|
|
share/man/man1/brew.1
|
|
|
|
share/man/whatis
|
|
|
|
]
|
|
|
|
|
2012-08-28 10:59:46 -07:00
|
|
|
def list_unbrewed
|
2013-07-31 15:18:37 -05:00
|
|
|
dirs = HOMEBREW_PREFIX.subdirs.map { |dir| dir.basename.to_s }
|
2012-08-28 10:59:46 -07:00
|
|
|
dirs -= %w[Library Cellar .git]
|
2012-11-10 11:26:47 -08:00
|
|
|
|
2013-07-31 15:18:37 -05:00
|
|
|
# Exclude the repository and cache, if they are located under the prefix
|
|
|
|
dirs.delete HOMEBREW_CACHE.relative_path_from(HOMEBREW_PREFIX).to_s
|
|
|
|
dirs.delete HOMEBREW_REPOSITORY.relative_path_from(HOMEBREW_PREFIX).to_s
|
2015-08-03 13:09:07 +01:00
|
|
|
dirs.delete "etc"
|
|
|
|
dirs.delete "var"
|
2012-11-12 09:56:45 -08:00
|
|
|
|
2013-07-31 15:18:37 -05:00
|
|
|
args = dirs + %w[-type f (]
|
|
|
|
args.concat UNBREWED_EXCLUDE_FILES.map { |f| %W[! -name #{f}] }.flatten
|
|
|
|
args.concat UNBREWED_EXCLUDE_PATHS.map { |d| %W[! -path #{d}] }.flatten
|
|
|
|
args.concat %w[)]
|
2012-11-10 11:26:47 -08:00
|
|
|
|
2012-08-28 10:59:46 -07:00
|
|
|
cd HOMEBREW_PREFIX
|
2015-08-03 13:09:07 +01:00
|
|
|
exec "find", *args
|
2012-08-28 10:59:46 -07:00
|
|
|
end
|
|
|
|
|
2014-09-06 19:12:03 -07:00
|
|
|
def filtered_list
|
|
|
|
names = if ARGV.named.empty?
|
2014-06-17 22:12:41 -05:00
|
|
|
HOMEBREW_CELLAR.subdirs
|
2012-08-28 10:59:46 -07:00
|
|
|
else
|
2015-08-03 13:09:07 +01:00
|
|
|
ARGV.named.map { |n| HOMEBREW_CELLAR+n }.select(&:exist?)
|
2012-08-28 10:59:46 -07:00
|
|
|
end
|
2015-08-03 13:09:07 +01:00
|
|
|
if ARGV.include? "--pinned"
|
2014-09-06 19:12:03 -07:00
|
|
|
pinned_versions = {}
|
|
|
|
names.each do |d|
|
|
|
|
keg_pin = (HOMEBREW_LIBRARY/"PinnedKegs"/d.basename.to_s)
|
2015-08-03 13:09:07 +01:00
|
|
|
if keg_pin.exist? || keg_pin.symlink?
|
2014-09-06 19:12:03 -07:00
|
|
|
pinned_versions[d] = keg_pin.readlink.basename.to_s
|
|
|
|
end
|
|
|
|
end
|
|
|
|
pinned_versions.each do |d, version|
|
2015-08-03 13:09:07 +01:00
|
|
|
puts "#{d.basename}".concat(ARGV.include?("--versions") ? " #{version}" : "")
|
2014-09-06 19:12:03 -07:00
|
|
|
end
|
|
|
|
else # --versions without --pinned
|
|
|
|
names.each do |d|
|
|
|
|
versions = d.subdirs.map { |pn| pn.basename.to_s }
|
2015-08-03 13:09:07 +01:00
|
|
|
next if ARGV.include?("--multiple") && versions.count < 2
|
|
|
|
puts "#{d.basename} #{versions*" "}"
|
2014-09-06 19:12:03 -07:00
|
|
|
end
|
2013-03-11 16:41:08 +01:00
|
|
|
end
|
|
|
|
end
|
2010-09-11 20:22:54 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
class PrettyListing
|
2015-08-03 13:09:07 +01:00
|
|
|
def initialize(path)
|
2014-07-01 13:32:53 -05:00
|
|
|
Pathname.new(path).children.sort_by { |p| p.to_s.downcase }.each do |pn|
|
2010-09-11 20:22:54 +01:00
|
|
|
case pn.basename.to_s
|
2015-08-03 13:09:07 +01:00
|
|
|
when "bin", "sbin"
|
2010-09-11 20:22:54 +01:00
|
|
|
pn.find { |pnn| puts pnn unless pnn.directory? }
|
2015-08-03 13:09:07 +01:00
|
|
|
when "lib"
|
2010-09-11 20:22:54 +01:00
|
|
|
print_dir pn do |pnn|
|
|
|
|
# dylibs have multiple symlinks and we don't care about them
|
2015-08-03 13:09:07 +01:00
|
|
|
(pnn.extname == ".dylib" || pnn.extname == ".pc") && !pnn.symlink?
|
2010-09-11 20:22:54 +01:00
|
|
|
end
|
|
|
|
else
|
|
|
|
if pn.directory?
|
|
|
|
if pn.symlink?
|
|
|
|
puts "#{pn} -> #{pn.readlink}"
|
|
|
|
else
|
|
|
|
print_dir pn
|
|
|
|
end
|
2014-06-07 17:49:07 -05:00
|
|
|
elsif Metafiles.list?(pn.basename.to_s)
|
2010-09-11 20:22:54 +01:00
|
|
|
puts pn
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-08-03 13:09:07 +01:00
|
|
|
def print_dir(root)
|
2010-09-11 20:22:54 +01:00
|
|
|
dirs = []
|
|
|
|
remaining_root_files = []
|
2015-08-03 13:09:07 +01:00
|
|
|
other = ""
|
2010-09-11 20:22:54 +01:00
|
|
|
|
|
|
|
root.children.sort.each do |pn|
|
|
|
|
if pn.directory?
|
|
|
|
dirs << pn
|
2015-08-06 15:45:52 +08:00
|
|
|
elsif block_given? && yield(pn)
|
2010-09-11 20:22:54 +01:00
|
|
|
puts pn
|
2015-08-03 13:09:07 +01:00
|
|
|
other = "other "
|
2010-09-11 20:22:54 +01:00
|
|
|
else
|
2015-08-03 13:09:07 +01:00
|
|
|
remaining_root_files << pn unless pn.basename.to_s == ".DS_Store"
|
2010-09-11 20:22:54 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
dirs.each do |d|
|
|
|
|
files = []
|
|
|
|
d.find { |pn| files << pn unless pn.directory? }
|
|
|
|
print_remaining_files files, d
|
|
|
|
end
|
|
|
|
|
|
|
|
print_remaining_files remaining_root_files, root, other
|
|
|
|
end
|
|
|
|
|
2015-08-03 13:09:07 +01:00
|
|
|
def print_remaining_files(files, root, other = "")
|
2010-09-11 20:22:54 +01:00
|
|
|
case files.length
|
|
|
|
when 0
|
|
|
|
# noop
|
|
|
|
when 1
|
|
|
|
puts files
|
|
|
|
else
|
|
|
|
puts "#{root}/ (#{files.length} #{other}files)"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|