Sha256: 29b0070f26c6fd32ab39711c8dde675ac15eff46dec8d0f6ee9a1b72475eede4

Contents?: true

Size: 1.49 KB

Versions: 6

Compression:

Stored size: 1.49 KB

Contents

#!/usr/bin/env ruby

require 'utils'
include Utils
require 'tins/go'
include Tins::GO

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

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

PATTERN is a pattern expression which is find the files. PATHS are the
directory and file paths 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
  -b          match also binary files
  -h          display this help

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

args = go 'I:a:rdDciebh'
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')
args['b'] ||= config.discover.binary
finder = Finder.new(
  :pattern => pattern,
  :args    => args,
  :roots   => roots,
  :config  => config
).search do |output|
  puts output
end
if args['e']
  edit_files finder.paths
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
utils-0.0.54 bin/discover
utils-0.0.53 bin/discover
utils-0.0.52 bin/discover
utils-0.0.51 bin/discover
utils-0.0.50 bin/discover
utils-0.0.49 bin/discover