Skip to content

Instantly share code, notes, and snippets.

@christianhujer
Last active February 2, 2016 05:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save christianhujer/9c28c591794581832eda to your computer and use it in GitHub Desktop.
Save christianhujer/9c28c591794581832eda to your computer and use it in GitHub Desktop.
Highlights incoherence in a directory tree.
#!/bin/bash
startDir=$1
wordToFind=$2
for dir in $(find $startDir -type d) ; do
echo -n "$dir:"
for file in $(find $dir --depth 1 -name "*.rb") ; do
if grep $wordToFind $file >/dev/null ; then
echo -n "X"
else
echo -n "_"
fi
done
echo
done | grep -C 9999 X
@markburns
Copy link

#!/usr/bin/env ruby
require 'colorize'
glob = ARGV[0]
search = ARGV[1]


class Writer
  def append(v)
    buffer << v.to_s
  end

  def to_s
    buffer
  end

  private

  def buffer
    @buffer ||= ""
  end
end


module Display
  class Directory < Struct.new(:raw)
    def to_s
      "\n#{raw}"
    end
  end

  class Dot < Struct.new(:raw)
    def to_s
      "."
    end
  end

  class Highlight < Struct.new(:raw)
    def to_s
      "X".red
    end
  end
end

def display_type_of(file, search)
  if File.directory?(file)
    Display::Directory
  else
    if file.include? search
     Display::Highlight
   else
     Display::Dot
   end
  end
end

writer = Writer.new

Dir.glob(glob).each do |f|
  klass = display_type_of(f, search)

  writer.append klass.new(f).to_s
end

puts writer

@markburns
Copy link

#!/usr/bin/env ruby
require 'colorize'

def puts(v)
  @buffer ||= ""
  @buffer << v
end

Dir.glob(ARGV[0]).each do |f|
 if File.directory?(f)
   puts "\n#{f}"
 else
   if File.read(f)[ARGV[1]]
     puts "X".red
   else
     puts "."
   end
 end
end

STDOUT.puts @buffer

@markburns
Copy link

result = Dir.glob(ARGV[0]).map do |f|
  if File.directory?(f)
    "\n#{f}"
  else
    if File.read(f)[ARGV[1]]
      "\e[0;31;49mX\e[0m"
    else
      "."
    end
  end
end.join ""

puts result

@markburns
Copy link

puts(Dir.glob(ARGV[0]).map do |f|
  File.directory?(f) ?  "\n#{f} " : (File.read(f)[ARGV[1]] ?  "\e[0;31;49mX\e[0m" : ".")
end.join(""))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment