Sha256: 2f4f7ea848442c2c2000a8f3d7854089ae668efb273bbdb1310b70e2ba0fa59f
Contents?: true
Size: 1.85 KB
Versions: 3
Compression:
Stored size: 1.85 KB
Contents
#!/usr/bin/env ruby # encoding: UTF-8 require 'utils' include Utils require 'spruz/go' include Spruz::GO def edit_files(pathes) editor = Utils::Editor.new do |config| config.wait = true end for path in pathes STDERR.puts "Edit #{path}" editor.edit(path) end end def usage puts <<-EOT Usage: #{File.basename($0)} [OPTS] PATTERN [PATHES] PATTERN is a pattern expression which is used to match against the content of the files. PATHES are the directory and file pathes that are searched. Options are -n PATTERN only search files whose names match fuzzy PATTERN -N PATTERN only search files whose names match regex PATTERN -s PATTERN skip lines that match fuzzy PATTERN -S PATTERN skip lines that match regex PATTERN -A NUMBER displays NUMBER lines of context after the match -B NUMBER displays NUMBER lines of context before the match -C NUMBER displays NUMBER lines of context around the match -l just list the pathes of the files with matches -L list only the path:linenumber of the files with matches -R interpret PATTERN argument as fuzzy not regex -c disable color output -i use case insensitive matches -I SUFFIX only include files with suffix SUFFIX in search -e open the matching files with edit command -a CSET use only character set CSET from PATTERN -h display this help EOT exit 1 end args = go 'I:A:B:C:s:S:n:N:a:RcilLeh' args['h'] and usage pattern = ARGV.shift or usage roots = (ARGV.empty? ? [ Dir.pwd ] : ARGV).map { |f| File.expand_path(f) } Term::ANSIColor.coloring = (STDIN.tty? && ENV['TERM'] !~ /dumb/) && !args['c'] STDOUT.sync = true grepper = Grepper.new( :pattern => pattern, :args => args, :roots => roots ).search case when args['e'] then edit_files grepper.pathes when args['l'] then puts grepper.pathes end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
utils-0.0.17 | bin/search |
utils-0.0.16 | bin/search |
utils-0.0.15 | bin/search |