[ANN] search-0.0.1

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/

···

--
we can deny everything, except that we have the possibility of being better. simply reflect on that.
h.h. the 14th dalai lama

Nice. Playing with it now.

Ps. Your gemspec needs a dependency on main.

Regards,
Jordan

···

On Dec 6, 5:45 pm, "ara.t.howard" <ara.t.how...@gmail.com> wrote:

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/
--
we can deny everything, except that we have the possibility of being
better. simply reflect on that.
h.h. the 14th dalai lama

Inspired by ack?

http://petdance.com/ack/

- rob

···

On Dec 6, 2007 6:45 PM, ara.t.howard <ara.t.howard@gmail.com> wrote:

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/

ooooops. thanks!

a @ http://codeforpeople.com/

···

On Dec 6, 2007, at 7:05 PM, MonkeeSage wrote:

Ps. Your gemspec needs a dependency on main.

--
we can deny everything, except that we have the possibility of being better. simply reflect on that.
h.h. the 14th dalai lama

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 :wink:

a @ http://codeforpeople.com/

···

On Dec 6, 2007, at 8:48 PM, Rob Sanheim wrote:

Inspired by ack?

Beyond grep: ack v3.7.0

--
share your knowledge. it's a way to achieve immortality.
h.h. the 14th dalai lama

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

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

···

On Dec 6, 9:20 pm, "ara.t.howard" <ara.t.how...@gmail.com> wrote:

On Dec 6, 2007, at 7:05 PM, MonkeeSage wrote:

> Ps. Your gemspec needs a dependency on main.

ooooops. thanks!

a @http://codeforpeople.com/
--
we can deny everything, except that we have the possibility of being
better. simply reflect on that.
h.h. the 14th dalai lama

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/

···

On 12/6/07, ara.t.howard <ara.t.howard@gmail.com> wrote:

On Dec 6, 2007, at 8:48 PM, Rob Sanheim wrote:

> Inspired by ack?
>
> Beyond grep: ack v3.7.0
>

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 :wink:

--
Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/

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

···

On Dec 6, 10:54 pm, MonkeeSage <MonkeeS...@gmail.com> wrote:

On Dec 6, 9:20 pm, "ara.t.howard" <ara.t.how...@gmail.com> wrote:

> On Dec 6, 2007, at 7:05 PM, MonkeeSage wrote:

> > Ps. Your gemspec needs a dependency on main.

> ooooops. thanks!

> a @http://codeforpeople.com/
> --
> we can deny everything, except that we have the possibility of being
> better. simply reflect on that.
> h.h. the 14th dalai lama

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

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

funny. for me it has been rails that's caused the change: too dang many files scattered all over the place :wink:

a @ http://codeforpeople.com/

···

On Dec 7, 2007, at 7:36 AM, Rick DeNatale wrote:

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/

--
we can deny everything, except that we have the possibility of being better. simply reflect on that.
h.h. the 14th dalai lama

"Rick DeNatale" <rick.denatale@gmail.com> writes:

···

On 12/6/07, ara.t.howard <ara.t.howard@gmail.com> wrote:

On Dec 6, 2007, at 8:48 PM, Rob Sanheim wrote:

> Inspired by ack?
>
> Beyond grep: ack v3.7.0
>

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 :wink:

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/

Also jpace (Jeff Pace) · GitHub, which is Ruby.

And of course also GNU grep, e.g.
  grep -r --include=*.c PATTERN DIR

Steve

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

···

On Dec 6, 11:12 pm, MonkeeSage <MonkeeS...@gmail.com> wrote:

On Dec 6, 10:54 pm, MonkeeSage <MonkeeS...@gmail.com> wrote:

> On Dec 6, 9:20 pm, "ara.t.howard" <ara.t.how...@gmail.com> wrote:

> > On Dec 6, 2007, at 7:05 PM, MonkeeSage wrote:

> > > Ps. Your gemspec needs a dependency on main.

> > ooooops. thanks!

> > a @http://codeforpeople.com/
> > --
> > we can deny everything, except that we have the possibility of being
> > better. simply reflect on that.
> > h.h. the 14th dalai lama

> NP. I really like this package, BTW. :slight_smile:

> 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

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/

···

On Dec 6, 2007, at 10:14 PM, MonkeeSage wrote:

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"

--
it is not enough to be compassionate. you must act.
h.h. the 14th dalai lama

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

a @ http://codeforpeople.com/

···

On Dec 6, 2007, at 10:49 PM, MonkeeSage wrote:

   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

--
we can deny everything, except that we have the possibility of being better. simply reflect on that.
h.h. the 14th dalai lama

> 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?

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. :slight_smile:

a @http://codeforpeople.com/
--
it is not enough to be compassionate. you must act.
h.h. the 14th dalai lama

Regards,
Jordan

···

On Dec 9, 1:23 pm, "ara.t.howard" <ara.t.how...@gmail.com> wrote:

On Dec 6, 2007, at 10:14 PM, MonkeeSage wrote: