class Utils::Grepper

def match(filename)

def match(filename)
  @filename = filename
  @output = []
  bn, s = File.basename(filename), File.stat(filename)
  if !s || s.directory? && @config.search.prune?(bn)
    @args[?v] and warn "Pruning #{filename.inspect}."
    prune
  end
  if s.file? && !@config.search.skip?(bn) &&
    (!@name_pattern || @name_pattern.match(bn))
  then
    File.open(filename, 'rb', encoding: Encoding::UTF_8) do |file|
      if @args[?b] && !@args[?g] || file.binary? != true
        @args[?v] and warn "Matching #{filename.inspect}."
        if @args[?f]
          @output << filename
        else
          match_lines file
        end
      else
        @args[?v] and warn "Skipping binary file #{filename.inspect}."
      end
    end
  else
    @args[?v] and warn "Skipping #{filename.inspect}."
  end
  unless @output.empty?
    case
    when @args[?g]
      @output.uniq!
      @output.each do |l|
        blamer = LineBlamer.for_line(l)
        if blame = blamer.perform
          blame.sub!(/^[0-9a-f^]+/) { Term::ANSIColor.yellow($&) }
          blame.sub!(/\(([^)]+)\)/) { "(#{Term::ANSIColor.red($1)})" }
          puts "#{blame.chomp} #{Term::ANSIColor.blue(l)}"
        end
      end
    when @args[?l], @args[?e], @args[?E], @args[?r]
      @output.uniq!
      @paths.concat @output
    else
      STDOUT.puts @output
    end
    @output.clear
  end
  self
end