Sha256: e1348ee227330394afbef4b147ffa769d1fc8de04623ab99b3debcdfbdd16f4d

Contents?: true

Size: 1.42 KB

Versions: 3

Compression:

Stored size: 1.42 KB

Contents

#!/usr/bin/env ruby

require 'utils'
include Utils
require 'spruz/go'
include Spruz::GO

def edit_files(pathes)
  editor = Utils::Editor.new do |config|
    config.wait = true
  end
  editor.edit(*pathes)
end

def usage
  puts <<-EOT
Usage: #{File.basename($0)} [OPTS] PATTERN [PATHES]

PATTERN is a pattern expression which is find the files. PATHES are the
directory and file pathes that are searched.

Options are

  -r          interpret PATTERN argument as regex not fuzzy
  -d          discover directories as well
  -D          discover only directories
  -c          disable color output
  -i          use case insensitive matches
  -e          open the matching files with edit command
  -a CSET     use only character set CSET from PATTERN
  -I SUFFIX   only include files with suffix SUFFIX during finding
  -h          display this help

Version is #{File.basename($0)} #{Utils::VERSION}.
  EOT
  exit 1
end

args = go 'I:a:rdDcieh'
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
config = Utils::Config::ConfigFile.new
config.parse_config_file File.expand_path('~/.utilsrc')
finder = Finder.new(
  :pattern => pattern,
  :args    => args,
  :roots   => roots,
  :config  => config
).search do |output|
  puts output
end
if args['e']
  edit_files finder.pathes
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
utils-0.0.21 bin/discover
utils-0.0.20 bin/discover
utils-0.0.19 bin/discover