Sha256: bcd16d1aa252de33ccbe0f323c0db8f277fedfb1696b0d58a5a8409f37d14683

Contents?: true

Size: 1.48 KB

Versions: 53

Compression:

Stored size: 1.48 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
  -v          be verbose
  -h          display this help

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

args = go 'I:a:rdDciebvh'
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.configure_from_paths
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

53 entries across 53 versions & 1 rubygems

Version Path
utils-0.2.4 bin/discover
utils-0.2.3 bin/discover
utils-0.2.2 bin/discover
utils-0.2.1 bin/discover
utils-0.2.0 bin/discover
utils-0.1.1 bin/discover
utils-0.1.0 bin/discover
utils-0.0.100 bin/discover
utils-0.0.99 bin/discover
utils-0.0.98 bin/discover
utils-0.0.97 bin/discover
utils-0.0.96 bin/discover
utils-0.0.95 bin/discover
utils-0.0.94 bin/discover
utils-0.0.93 bin/discover
utils-0.0.92 bin/discover
utils-0.0.91 bin/discover
utils-0.0.90 bin/discover
utils-0.0.89 bin/discover
utils-0.0.88 bin/discover