[ANN] search-0.0.1

A

ara.t.howard

NAME
search

SYNOPSIS
search Directory re re* [options]+

URIS
http://codeforpeople.com/lib/ruby/
http://rubyforge.org/projects/codeforpeople/

INSTALL
gem install search

DESCRIPTION
search is a combination of find and grep. it recursively traverses a
directory and searches all files for one or more regular expressions,
printing each file containing matches on stdout. by default it
ignores
repo directories like .cvs|.svn|.rcs

PARAMETERS
Directory (1 -> Directory)
re (-2 -> re)
--Filter=Filter, -F (0 ~> list_of_string(Filter=.*))
limit searchs to files matching these regular expressions. may be
given more than once
--All=All, -A (0 ~> All)
*all* Filters must match to be considered a success. default
is that
*any* Filter pattern matching is considered a success
--Ignore=Ignore, -I (0 ~> list_of_string(Ignore=.svn,.cvs,.rcs))
ignore any file matching this list of patterns default
(.svn|.cvs|.rcs)
--Sensitive, -S
conisder all Filters case sensitive. default is case insensitive
--file=file, -f (0 ~> file)
load a file full of patterns, one per line
--sensitive, -s
conisder all patterns case sensitive. default case insensitive
--any, -a
*any* pattern match is considered success. default is that *all*
patterns must match
--verbose, -v
print every match with lineno information
--help, -h


enjoy.

a @ http://codeforpeople.com/
 
M

MonkeeSage

NAME
search

SYNOPSIS
search Directory re re* [options]+

URIS
http://codeforpeople.com/lib/ruby/
http://rubyforge.org/projects/codeforpeople/

INSTALL
gem install search

DESCRIPTION
search is a combination of find and grep. it recursively traverses a
directory and searches all files for one or more regular expressions,
printing each file containing matches on stdout. by default it
ignores
repo directories like .cvs|.svn|.rcs

PARAMETERS
Directory (1 -> Directory)
re (-2 -> re)
--Filter=Filter, -F (0 ~> list_of_string(Filter=.*))
limit searchs to files matching these regular expressions. may be
given more than once
--All=All, -A (0 ~> All)
*all* Filters must match to be considered a success. default
is that
*any* Filter pattern matching is considered a success
--Ignore=Ignore, -I (0 ~> list_of_string(Ignore=.svn,.cvs,.rcs))
ignore any file matching this list of patterns default
(.svn|.cvs|.rcs)
--Sensitive, -S
conisder all Filters case sensitive. default is case insensitive
--file=file, -f (0 ~> file)
load a file full of patterns, one per line
--sensitive, -s
conisder all patterns case sensitive. default case insensitive
--any, -a
*any* pattern match is considered success. default is that *all*
patterns must match
--verbose, -v
print every match with lineno information
--help, -h

enjoy.

a @http://codeforpeople.com/

Nice. Playing with it now.

Ps. Your gemspec needs a dependency on main.

Regards,
Jordan
 
R

Rob Sanheim

NAME
search

SYNOPSIS
search Directory re re* [options]+

URIS
http://codeforpeople.com/lib/ruby/
http://rubyforge.org/projects/codeforpeople/

INSTALL
gem install search

DESCRIPTION
search is a combination of find and grep. it recursively traverses a
directory and searches all files for one or more regular expressions,
printing each file containing matches on stdout. by default it
ignores
repo directories like .cvs|.svn|.rcs

PARAMETERS
Directory (1 -> Directory)
re (-2 -> re)
--Filter=Filter, -F (0 ~> list_of_string(Filter=.*))
limit searchs to files matching these regular expressions. may be
given more than once
--All=All, -A (0 ~> All)
*all* Filters must match to be considered a success. default
is that
*any* Filter pattern matching is considered a success
--Ignore=Ignore, -I (0 ~> list_of_string(Ignore=.svn,.cvs,.rcs))
ignore any file matching this list of patterns default
(.svn|.cvs|.rcs)
--Sensitive, -S
conisder all Filters case sensitive. default is case insensitive
--file=file, -f (0 ~> file)
load a file full of patterns, one per line
--sensitive, -s
conisder all patterns case sensitive. default case insensitive
--any, -a
*any* pattern match is considered success. default is that *all*
patterns must match
--verbose, -v
print every match with lineno information
--help, -h


enjoy.

a @ http://codeforpeople.com/

Inspired by ack?

http://petdance.com/ack/

- rob
http://robsanheim.com
 
M

MonkeeSage

ooooops. thanks!

a @http://codeforpeople.com/

NP. I really like this package, BTW. :)

A problem I just ran into is dot-files (e.g., .tesfile). It looks like
the glob pattern (constructued on line 115) is the problem. In a
directory with .testfile, I get this output:

$ ruby -w 'p Dir["./**/**"]'
[]

$ ruby -e 'p Dir["./.*"]'
["..", ".testfile", "."]

But adding a dot to the double star doesn't work correctly (i.e.,
"./.**/**" get treated as "./../*", doh). I'm not sure there's any
easy way to do it with Dir#glob.

Regards,
Jordan
 
M

MonkeeSage

On Dec 6, 2007, at 7:05 PM, MonkeeSage wrote:
ooooops. thanks!
a @http://codeforpeople.com/

NP. I really like this package, BTW. :)

A problem I just ran into is dot-files (e.g., .tesfile). It looks like
the glob pattern (constructued on line 115) is the problem. In a
directory with .testfile, I get this output:

$ ruby -w 'p Dir["./**/**"]'
[]

$ ruby -e 'p Dir["./.*"]'
["..", ".testfile", "."]

But adding a dot to the double star doesn't work correctly (i.e.,
"./.**/**" get treated as "./../*", doh). I'm not sure there's any
easy way to do it with Dir#glob.

Regards,
Jordan

Not sure what the difference in performance is with Find#fidn vs.
Dir#glob, but as a drop-in replacement...

--- search.old 2007-12-06 23:09:34.000000000 -0600
+++ search 2007-12-06 23:10:13.000000000 -0600
@@ -1,6 +1,7 @@
#! /usr/bin/env ruby

require 'main'
+require 'find'

Main {
description <<-txt
@@ -112,9 +113,8 @@
end

def each_entry_with_lines
- glob = File.join param['Directory'].value, '**', '**'
filters = build_filter_list
- Dir.glob(glob) do |entry|
+ Find.find param['Directory'].value do |entry|
next unless filters.match(entry)
test ?f, entry or next
lines = IO.readlines entry rescue next

Might I also suggest that you filter on the file's basename? One might
except...

search -F "^\." -a . "blah"

....to match all dot-files in ./ which contain "blah", but you actually
need something like this since you're running the filter against the
absolute path...

search -F ".*/*\." -a . "blah"

Regards,
Jordan
 
M

MonkeeSage

NP. I really like this package, BTW. :)
A problem I just ran into is dot-files (e.g., .tesfile). It looks like
the glob pattern (constructued on line 115) is the problem. In a
directory with .testfile, I get this output:
$ ruby -w 'p Dir["./**/**"]'
[]
$ ruby -e 'p Dir["./.*"]'
["..", ".testfile", "."]
But adding a dot to the double star doesn't work correctly (i.e.,
"./.**/**" get treated as "./../*", doh). I'm not sure there's any
easy way to do it with Dir#glob.
Regards,
Jordan

Not sure what the difference in performance is with Find#fidn vs.
Dir#glob, but as a drop-in replacement...

--- search.old 2007-12-06 23:09:34.000000000 -0600
+++ search 2007-12-06 23:10:13.000000000 -0600
@@ -1,6 +1,7 @@
#! /usr/bin/env ruby

require 'main'
+require 'find'

Main {
description <<-txt
@@ -112,9 +113,8 @@
end

def each_entry_with_lines
- glob = File.join param['Directory'].value, '**', '**'
filters = build_filter_list
- Dir.glob(glob) do |entry|
+ Find.find param['Directory'].value do |entry|
next unless filters.match(entry)
test ?f, entry or next
lines = IO.readlines entry rescue next

Might I also suggest that you filter on the file's basename? One might
except...

search -F "^\." -a . "blah"

...to match all dot-files in ./ which contain "blah", but you actually
need something like this since you're running the filter against the
absolute path...

search -F ".*/*\." -a . "blah"

Regards,
Jordan

Testing on a few different directories and filter patterns, the
Find#find version (w/ filters.match(File.basename(entry))) appears to
be about the same a the Dir#glob version for speed (about two tenths
of a second slower for a directory with 2109 files and a filter
pattern of ".*").

Regards,
Jordan
 
R

Rick DeNatale

yeah i blogged that a while back

http://drawohara.com/post/19092746

bil kleb forwarded it my way. curiously, it'd just written search a
few days before. of course ack is more fully featured - but i
figured i'd better release since ack is in perl and ruby outght to be
represent'n ;-)

Hmmm, something must be in the air. Shortly after reading this, my
RSS reader delivered a post from Peter Cooper pointing to this:
http://rak.rubyforge.org/
 
A

ara.t.howard

def each_entry_with_lines
- glob = File.join param['Directory'].value, '**', '**'
filters = build_filter_list
- Dir.glob(glob) do |entry|
+ Find.find param['Directory'].value do |entry|
next unless filters.match(entry)
test ?f, entry or next
lines = IO.readlines entry rescue next

Might I also suggest that you filter on the file's basename? One
might
except...

search -F "^\." -a . "blah"

...to match all dot-files in ./ which contain "blah", but you
actually
need something like this since you're running the filter against the
absolute path...

search -F ".*/*\." -a . "blah"

Regards,
Jordan

Testing on a few different directories and filter patterns, the
Find#find version (w/ filters.match(File.basename(entry))) appears to
be about the same a the Dir#glob version for speed (about two tenths
of a second slower for a directory with 2109 files and a filter
pattern of ".*").

Regards,
Jordan

i'll incorporate something like you suggest and re-release. thanks
for the feedback!

a @ http://codeforpeople.com/
 
A

ara.t.howard

Might I also suggest that you filter on the file's basename? One might
except...

search -F "^\." -a . "blah"

...to match all dot-files in ./ which contain "blah", but you actually
need something like this since you're running the filter against the
absolute path...

search -F ".*/*\." -a . "blah"

that's kind of interesting - why not simply

search . blah -F /.

though?

this should work unless you happen to have dot-directories too. if so
you can use

search . blah -F '.[^/]+$'

which would filter only dot-files though. i like the filter being
able to filter certain directories too. i could add an option to
alter it's behavior to only match basenames, or add a new option.

thoughts?

a @ http://codeforpeople.com/
 
M

MonkeeSage

that's kind of interesting - why not simply

search . blah -F /.

though?

Cause I'm not smart, hehe. That works fine.
this should work unless you happen to have dot-directories too. if so
you can use

search . blah -F '.[^/]+$'

which would filter only dot-files though. i like the filter being
able to filter certain directories too. i could add an option to
alter it's behavior to only match basenames, or add a new option.

thoughts?

I don't think you need change anything since there will always be at
least one "/" (and it's just as easy to affix the pattern with / as
type an extra switch). My brain sometimes malfunctions. :)
a @http://codeforpeople.com/

Regards,
Jordan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,710
Latest member
bernietqt

Latest Threads

Top