#!/usr/bin/env ruby STDOUT.sync=true if ARGV.size == 0 puts "Usage: findit where pattern" puts "findit -h for help" exit elsif ARGV.first =~ /^(-h|--help)$/ puts "Usage: findit where pattern" puts puts "findit finds all files matching the contents of" puts "pattern starting in the where directory. It searches" puts "recursively throughout the where directory." puts puts "Options:" puts " -h, --help shows this help" puts puts "Example:" puts " Find all files whose contains match 'abc def ghi':" puts " findit ./ abc def ghi" puts puts "Files whose name matches the below patterns will be" puts "ignored:" DATA.each { |pattern| puts " #{pattern}" } puts puts "findit is a wrapper to find and grep." puts puts "Author: zach.dennis@gmail.com" exit end where = ARGV.shift what = "'" + ARGV.join( " " ) + "'" ignore = DATA.readlines.map{|line| line.chomp}.join("|") cmd = "find #{where} -type f -exec grep -Hn #{what} {} \\; | grep -E -v \"#{ignore}\"" system cmd # file patterns to ignore __END__ \\.svn \\.log \\.project CVS \\.dylib \\.o