Made find_keyword case insensitive
[mwamko.git] / find_keyword
blobb4ff85e8a9ac2f354b34dbadd02d3fa953d3a33a
1 #!/usr/bin/env ruby
3 # Almost like:
4 # find . -type f | grep -v log/ | grep -v lib/ | xargs grep -in comet
7 SCRIPT_DIR = File.dirname(File.expand_path(__FILE__))
8 SCRIPT_NAME = $0.split('/')[-1]
10 Dir.chdir(SCRIPT_DIR)
12 `find -type f`.each do |file_name|
14 file_name.chomp!
16 case file_name
17 when /\.$/, /\.git/, /~$/
18 # Ignore these
20 when /^\.\/lib\/dict\/words/, /^\.\/log\//
21 # And these
23 when /^\.\/vendors\//, /^\.\/doc\//
24 # Even ignore the Vendors and Documentation files!
26 else
28 # Ignore Image files
29 next if `file -i -b #{file_name}` =~ /^image/
31 found = false
32 File.open(file_name).each_with_index do |line_text, line_number|
33 if line_text.downcase =~ /#{ARGV[0].downcase}/
34 puts file_name.rjust(75, '=') + '=' * 5 unless found
35 found = true
36 print "#{line_number.to_s.rjust(5)}: "
37 if line_text.size < 72
38 puts line_text
39 else
40 puts line_text[0..69] + '...'
41 end
42 end
43 end
44 puts if found
46 end
47 end