Created
July 14, 2014 11:36
-
-
Save richmidwinter/56ae331d9a0e0ebf8382 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
@file_patterns = File.readlines("#{Dir.home}/.cuignore") | |
@ptn = ARGV[0] | |
def search(f) | |
res = {} | |
h = File.open(f, 'r') | |
h.each_line {|line| | |
if line.index(@ptn) | |
begin | |
hline = line.gsub(@ptn, "\033[32m#{@ptn}\033[0m") | |
res[h.lineno] = hline | |
rescue ArgumentError => e | |
puts | |
puts "\033[36m#{f}\033[0m: \033[31m#{e}\033[0m" | |
end | |
end | |
} | |
if res.size > 0 | |
puts | |
puts "\033[36m#{f}\033[0m:" | |
res.keys.each do |key| | |
puts "#{key}:#{res[key]}" | |
end | |
end | |
end | |
def list(dir) | |
Dir.foreach(dir) do |fname| | |
next if fname == '.' or fname == '..' or @file_patterns.any? { |p| File.fnmatch(p.strip, File.basename(fname)) } | |
f = File.join(dir, fname) | |
if File.directory?(f) | |
list(f) | |
else | |
search(f) | |
end | |
end | |
end | |
list(".") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment