Fixing database_for_scripts library
[mwamko.git] / find_keyword
blob3166a0c243d483347e6d9180f890500dd28885b5
1 #!/usr/bin/env ruby
3 # Almost like:
4 # find . -type f | grep -v log/ | grep -v lib/ | xargs grep -in KEYWORD
6 SCRIPT_DIR = File.dirname(File.expand_path(__FILE__))
7 SCRIPT_NAME = $0.split('/')[-1]
9 Dir.chdir(SCRIPT_DIR)
11 `find -type f`.each do |file_name|
13 file_name.chomp!
15 case file_name
16 when /\.$/, /\.git/, /~$/
17 # Ignore these
19 when /^\.\/lib\/dict\/words/, /^\.\/log\//
20 # And these
22 when /^\.\/vendor\//, /^\.\/doc\//
23 # Even ignore the Vendors and Documentation files!
25 else
27 # Ignore Image files
28 next if `file -i -b #{file_name}` =~ /^image/
30 found = false
31 File.open(file_name).each_with_index do |line_text, line_number|
32 if line_text.downcase =~ /#{ARGV[0].downcase}/
33 puts file_name.rjust(75, '=') + '=' * 5 unless found
34 found = true
35 print "#{line_number.to_s.rjust(5)}: "
36 if line_text.size < 72
37 puts line_text
38 else
39 puts line_text[0..69] + '...'
40 end
41 end
42 end
43 puts if found
45 end
46 end