Added Synopsis to the find_keyword command line tool, moved it into script/.
[mwamko.git] / script / find_keyword
blob038b623dc4bf476225804039b3f50df3a82dd276
1 #!/usr/bin/env ruby
3 # Almost like:
4 # find . -type f | grep -v log/ | grep -v lib/ | xargs grep -in KEYWORD
7 SCRIPT_DIR = File.dirname(File.expand_path(__FILE__))
8 SCRIPT_NAME = $0.split('/')[-1]
10 Dir.chdir(SCRIPT_DIR)
13 if ARGV.size != 1
15 STDERR.puts "SYNOPSIS:"
16 STDERR.puts " #{SCRIPT_NAME} \e[4mKEYWORD\e[24m"
17 STDERR.puts ""
18 STDERR.puts "DESCRIPTION:"
19 STDERR.puts " Show occurrences of KEYWORD in relative files of the project."
21 exit
22 end
25 `find -type f`.each do |file_name|
27 file_name.chomp!
29 case file_name
30 when /^\.\/doc\//, /^\.\/vendor\//
31 # Ignore the Vendors and Documentation files!
33 when /\.$/, /\.git/, /~$/
34 # Also ignore these
36 when /^\.\/lib\/dict\/words/, /^\.\/log\//
37 # And these
39 else
41 # Ignore Image files
42 next if `file -i -b #{file_name}` =~ /^image/
44 found = false
45 File.open(file_name).each_with_index do |line_text, line_number|
46 if line_text.downcase =~ /#{ARGV[0].downcase}/
47 puts file_name.rjust(75, '=') + '=' * 5 unless found
48 found = true
49 print "#{line_number.to_s.rjust(5)}: "
50 if line_text.size < 72
51 puts line_text
52 else
53 puts line_text[0..69] + '...'
54 end
55 end
56 end
57 puts if found
59 end
60 end