Class: PrettyListing

Inherits:
Object
  • Object
show all
Defined in:
brew/Library/Homebrew/cmd/list.rb

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ PrettyListing

Returns a new instance of PrettyListing



154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# File 'brew/Library/Homebrew/cmd/list.rb', line 154

def initialize(path)
  Pathname.new(path).children.sort_by { |p| p.to_s.downcase }.each do |pn|
    case pn.basename.to_s
    when "bin", "sbin"
      pn.find { |pnn| puts pnn unless pnn.directory? }
    when "lib"
      print_dir pn do |pnn|
        # dylibs have multiple symlinks and we don't care about them
        (pnn.extname == ".dylib" || pnn.extname == ".pc") && !pnn.symlink?
      end
    when ".brew"
      next # Ignore .brew
    else
      if pn.directory?
        if pn.symlink?
          puts "#{pn} -> #{pn.readlink}"
        else
          print_dir pn
        end
      elsif Metafiles.list?(pn.basename.to_s)
        puts pn
      end
    end
  end
end

Instance Method Details



180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
# File 'brew/Library/Homebrew/cmd/list.rb', line 180

def print_dir(root)
  dirs = []
  remaining_root_files = []
  other = ""

  root.children.sort.each do |pn|
    if pn.directory?
      dirs << pn
    elsif block_given? && yield(pn)
      puts pn
      other = "other "
    else
      remaining_root_files << pn unless pn.basename.to_s == ".DS_Store"
    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


205
206
207
208
209
210
211
# File 'brew/Library/Homebrew/cmd/list.rb', line 205

def print_remaining_files(files, root, other = "")
  if files.length == 1
    puts files
  elsif files.length > 1
    puts "#{root}/ (#{files.length} #{other}files)"
  end
end