[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

[ANN] search-0.0.1

ara.t.howard

12/6/2007 11:45:00 PM


NAME
search

SYNOPSIS
search Directory re re* [options]+

URIS
http://codeforpeople.com...
http://rubyforge.org/projects/code...

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




13 Answers

MonkeeSage

12/7/2007 2:02:00 AM

0

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...
> http://rubyforge.org/projects/code...
>
> 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://codeforp...
> --
> 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

ara.t.howard

12/7/2007 3:20:00 AM

0


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

> Ps. Your gemspec needs a dependency on main.


ooooops. thanks!

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




Rob Sanheim

12/7/2007 3:49:00 AM

0

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...
> http://rubyforge.org/projects/code...
>
> 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://codeforp...

Inspired by ack?

http://petdanc...

- rob
http://robs...

ara.t.howard

12/7/2007 4:29:00 AM

0


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

> Inspired by ack?
>
> http://petdanc...
>


yeah i blogged that a while back

http://drawohara.com/pos...

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 ;-)

a @ http://codeforp...
--
share your knowledge. it's a way to achieve immortality.
h.h. the 14th dalai lama



MonkeeSage

12/7/2007 4:55:00 AM

0

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://codeforp...
> --
> 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. :)

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

MonkeeSage

12/7/2007 5:12:00 AM

0

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://codeforp...
> > --
> > 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. :)
>
> 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

MonkeeSage

12/7/2007 5:49:00 AM

0

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://codeforp...
> > > --
> > > 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. :)
>
> > 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

Rick DeNatale

12/7/2007 2:37:00 PM

0

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?
> >
> > http://petdanc...
> >
>
>
> yeah i blogged that a while back
>
> http://drawohara.com/pos...
>
> 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.ruby...

--
Rick DeNatale

My blog on Ruby
http://talklikeaduck.denh...

ara.t.howard

12/7/2007 9:05:00 PM

0


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

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

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




ara.t.howard

12/7/2007 9:06:00 PM

0


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.ruby...
>

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

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