Created
August 27, 2011 07:02
-
-
Save nanki/1175089 to your computer and use it in GitHub Desktop.
file filter: $ ff -@bin -_test.rb controller ...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'open3' | |
EXCLUDE_EXTENTSONS = %w(psd gif jpg png DS_Store tmp JPG PNG swp swf o bundle dylib so) | |
EXCLUDE_FROM_CURRENT = %w(estraier tmp log coverage build) | |
subdirs = Dir.glob("*") | |
subdirs -= EXCLUDE_FROM_CURRENT | |
def process_args(argv, _subdirs, _patterns) | |
subdirs, patterns = argv.partition{|v| /^([-+])?@/ === v} | |
_patterns += patterns | |
subdirs.each do |dir| | |
case dir | |
when /^@(.*)/ | |
_subdirs = [$1] | |
when /^-@(.*)/ | |
_subdirs -= [$1] | |
when /^\+@(.*)/ | |
_subdirs += [$1] | |
end | |
end | |
[_subdirs, _patterns] | |
end | |
patterns = [] | |
subdirs, patterns = process_args(open('.ffrc').read.split, subdirs, patterns) if File.exist? '.ffrc' | |
subdirs, patterns = process_args(ARGV, subdirs, patterns) | |
ext = EXCLUDE_EXTENTSONS.map{|ext| "! -name '*.#{ext}' "}.join | |
patterns = patterns.map{|v| "#{/^-/ === v ? '!' : ''} -path '*#{v.sub(/^-/, '')}*' "}.join | |
cmd = "find #{subdirs.map{|v| v.gsub(/ /, '\ ')}.join(' ')} -type f #{ext} ! -path '*/.git/*' ! -path '*/.svn/*' #{patterns}" | |
found = false | |
_, stdout, _ = *Open3.popen3(cmd) | |
stdout.each do |line| | |
found = true | |
puts line | |
end | |
unless found | |
$stderr.puts "Not found" | |
exit 1 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment