Skip to content

Instantly share code, notes, and snippets.

@jimweirich
Created March 15, 2011 21:46
Show Gist options
  • Save jimweirich/871559 to your computer and use it in GitHub Desktop.
Save jimweirich/871559 to your computer and use it in GitHub Desktop.
Find in Code
#!/usr/bin/env ruby
# -*- ruby -*-
begin
require 'rubygems'
rescue LoadError
end
exts = ['.rb', '.rhtml', '.erb', '.builder', '.haml', '.css', '.coffee' ]
if ARGV[0] =~ /^(\+|\.[a-zA-Z0-9]+)$/
if ARGV[0] == '+'
ARGV.shift
else
exts = []
end
while ARGV[0] =~ /^\.[a-zA-Z0-9]+$/
exts << ARGV.shift
end
end
ext = "{" + exts.join(',') + "}"
if ARGV.size < 1
puts "Usage: #{File.basename($0)} [.ext ...] pattern ..."
puts "(searching #{ext} files)"
exit 1
end
require 'rake'
status = 1
FileList["**/*#{ext}"].egrep(Regexp.new(ARGV.join('.*'), Regexp::IGNORECASE)) do |fn, count, line|
puts "#{fn}:#{count}:#{line}"
status = 0
end
exit(status)
@flores
Copy link

flores commented Mar 15, 2011

Sweet!

Adding an exec option would be so hot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment