rak 0.9 → 1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (6) hide show
  1. data/History.txt +11 -0
  2. data/README.txt +3 -3
  3. data/bin/rak +50 -20
  4. data/lib/rak.rb +1 -1
  5. data/spec/rak_spec.rb +11 -4
  6. metadata +65 -43
@@ -1,4 +1,15 @@
1
1
 
2
+ == 1.0 / 2009-09-27
3
+
4
+ * MinGW is a valid Windows platform type.
5
+ * Can use ~bang and ~ques in a regex and they will be turned into ! and ?
6
+ This is to get around bash.
7
+ * Added -k negative file match option (Contributed by Juozas Gaigalas')
8
+ * Added .cc and .hpp to the C++ file types
9
+ * Added Vala file types
10
+ * 20% faster on average
11
+ * Moved to Github
12
+
2
13
  == 0.9 / 2008-02-03
3
14
 
4
15
  * Added .rake to ruby files
data/README.txt CHANGED
@@ -1,9 +1,9 @@
1
1
  rak
2
- by Daniel Lucraft
3
- http://rubyforge.org/projects/rak
2
+ http://rubyforge.org/projects/rak
3
+ Daniel Lucraft (http://danlucraft.com/blog/)
4
4
 
5
5
  == DESCRIPTION:
6
-
6
+
7
7
  Replacement for grep. Recursively scans directories to match a given
8
8
  Ruby regular expression. Prints highlighted results.
9
9
 
data/bin/rak CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  require 'rubygems'
4
4
 
5
- if RUBY_PLATFORM =~ /mswin/
5
+ if RUBY_PLATFORM =~ /mswin|mingw/
6
6
  begin
7
7
  require 'win32console'
8
8
  rescue LoadError
@@ -20,8 +20,6 @@ rescue LoadError
20
20
  $use_onig = false
21
21
  end
22
22
 
23
- $use_onig = false
24
-
25
23
  class Rak
26
24
  VERSION = "0.9"
27
25
 
@@ -42,7 +40,7 @@ END
42
40
  FILE_TYPES = {
43
41
  :asm => %w( .s .S ),
44
42
  :cc => %w( .c .h .xs ),
45
- :cpp => %w( .cpp .m .h .C .H ),
43
+ :cpp => %w( .cpp .cc .m .h .hpp .C .H ),
46
44
  :csharp => %w( .cs ),
47
45
  :css => %w( .css ),
48
46
  :elisp => %w( .el ),
@@ -69,6 +67,7 @@ END
69
67
  :tex => %w( .tex .cls .sty ),
70
68
  :text => %w( .txt .text ),
71
69
  :tt => %w( .tt .tt2 .ttml ),
70
+ :vala => %w( .vala .vapi ),
72
71
  :vb => %w( .bas .cls .frm .ctl .vb .resx ),
73
72
  :vim => %w( .vim ),
74
73
  :yaml => %w( .yaml .yml ),
@@ -134,6 +133,7 @@ END
134
133
  [ '--before-context', '-B', GetoptLong::REQUIRED_ARGUMENT ],
135
134
  [ '--context', '-C', GetoptLong::OPTIONAL_ARGUMENT ],
136
135
  [ '-g', GetoptLong::REQUIRED_ARGUMENT ],
136
+ [ '-k', GetoptLong::REQUIRED_ARGUMENT ],
137
137
  [ '-x', '--line-regexp', GetoptLong::NO_ARGUMENT ],
138
138
  [ '-s', '--line-start', GetoptLong::NO_ARGUMENT ],
139
139
  [ '-e', '--line-end', GetoptLong::NO_ARGUMENT ]
@@ -170,6 +170,7 @@ END
170
170
  opt[:before_context] = 0
171
171
  opt[:collect_context] = false
172
172
  opt[:filename_regex] = nil
173
+ opt[:neg_filename_regex] = nil
173
174
 
174
175
  # if redirected (RAK_TEST allows us to redirect in testing and still
175
176
  # get the non-redirected defaults).
@@ -291,6 +292,8 @@ END
291
292
  opt[:after_context] = val
292
293
  when '-g'
293
294
  opt[:filename_regex] = arg
295
+ when '-k'
296
+ opt[:neg_filename_regex] = arg
294
297
  when '-x'
295
298
  opt[:match_whole_lines] = true
296
299
  when '-s'
@@ -452,6 +455,16 @@ END
452
455
  files = files.select {|fn| fn =~ fn_re }
453
456
  end
454
457
 
458
+ # filter based on -k=REGEX
459
+ if opt[:neg_filename_regex]
460
+ if $use_onig
461
+ fn_re = Oniguruma::ORegexp.new(opt[:neg_filename_regex])
462
+ else
463
+ fn_re = Regexp.new(opt[:neg_filename_regex])
464
+ end
465
+ files = files.reject {|fn| fn =~ fn_re }
466
+ end
467
+
455
468
  # remove the "./"
456
469
  files.map! {|fn| fn[0..1] == "./" ? fn[2..-1] : fn}
457
470
 
@@ -469,16 +482,20 @@ END
469
482
  rescue
470
483
  line = ""
471
484
  end
472
- if line =~ /^#!/
473
- if line =~ /\b(ruby|perl|php|python)\b/
474
- return "."+FILE_TYPES[$1.intern].first
475
- elsif line =~ /\b(bash|csh|ksh|zsh)\b/
476
- return ".sh"
485
+ begin
486
+ if line =~ /^#!/
487
+ if line =~ /\b(ruby|perl|php|python)\b/
488
+ return "."+FILE_TYPES[$1.intern].first
489
+ elsif line =~ /\b(bash|csh|ksh|zsh)\b/
490
+ return ".sh"
491
+ end
492
+ else
493
+ if line =~ /\Q<?xml /
494
+ return ".xml"
477
495
  end
478
- else
479
- if line =~ /\Q<?xml /
480
- return ".xml"
481
496
  end
497
+ rescue
498
+ return nil
482
499
  end
483
500
  return false
484
501
  end
@@ -500,6 +517,7 @@ END
500
517
  if opt[:match_line_ends]
501
518
  str = str + "$"
502
519
  end
520
+ str = str.gsub("~bang", "!").gsub("~ques", "?")
503
521
  if $use_onig
504
522
  if opt[:ignore_case]
505
523
  re = Oniguruma::ORegexp.new(str, :options => Oniguruma::OPTION_IGNORECASE)
@@ -523,10 +541,7 @@ END
523
541
  # the match method based on them. This is gives a 2x speedup over
524
542
  # the alternative.
525
543
  def self.compile_match_file
526
- code = ""
527
- def code.<<(str)
528
- self.concat(str + "\n")
529
- end
544
+ code = []
530
545
  code << %{def self.match_file(re, fn) }
531
546
  code << %{ displayed_filename = false }
532
547
  code << %{ count = 0 }
@@ -544,7 +559,19 @@ END
544
559
  code << %{ f = fn }
545
560
  code << %{ end }
546
561
 
547
- code << %{ f.each_line do |line| }
562
+ code << %{ all = f.read }
563
+ # code << %{ p fn }
564
+ # code << %{ all =~ re rescue p all }
565
+ code << %{ if all !~ re and not opt[:invert_match] and not opt[:print_entire_line_if_no_match] }
566
+ if opt[:print_file_if_no_match]
567
+ code << %{ if count == 0 }
568
+ code << %{ puts fn }
569
+ code << %{ end }
570
+ end
571
+ code << %{ return }
572
+ code << %{ end }
573
+
574
+ code << %{ all.each_line do |line| }
548
575
  code << %{ i += 1 }
549
576
  code << %{ rest = line }
550
577
  code << %{ while md = re.match(rest) }
@@ -651,7 +678,9 @@ END
651
678
  if opt[:invert_match]
652
679
  code << %{ puts "\#{fn}:\#{i-count}" }
653
680
  else
654
- code << %{ puts "\#{fn}:\#{count}" }
681
+ code << %{ if count > 0 }
682
+ code << %{ puts "\#{fn}:\#{count}" }
683
+ code << %{ end }
655
684
  end
656
685
  end
657
686
  if opt[:print_file_if_match]
@@ -666,7 +695,7 @@ END
666
695
  code << %{ end }
667
696
  end
668
697
  code << %{end }
669
- module_eval code
698
+ module_eval code.join("\n")
670
699
  end
671
700
 
672
701
  def self.print_highlighted(prefix, line, matches)
@@ -755,7 +784,8 @@ File finding:
755
784
 
756
785
  File inclusion/exclusion:
757
786
  -n No descending into subdirectories
758
- -g REGEX Only search in file matching REGEX.
787
+ -g REGEX Only search in files matching REGEX.
788
+ -k REGEX Only search in files not matching REGEX.
759
789
  -a, --all All files, regardless of extension (but still skips
760
790
  blib, pkg, CVS, _darcs, .git, .pc, RCS, SCCS and .svn dirs)
761
791
  --ruby Include only Ruby files.
data/lib/rak.rb CHANGED
@@ -1,4 +1,4 @@
1
1
 
2
2
  class Rak
3
- VERSION = "0.9"
3
+ VERSION = "1.0"
4
4
  end
@@ -158,14 +158,10 @@ Cap
158
158
  END
159
159
  end
160
160
 
161
-
162
161
  it "-c prints only the number of matches found per file" do
163
162
  t=<<END
164
- quux.py:0
165
163
  dir1/bar.rb:2
166
164
  foo.rb:2
167
- shebang:0
168
- Rakefile:0
169
165
  END
170
166
  sort_lines(strip_ansi(%x{rak Pik -c})).should == sort_lines(t)
171
167
  end
@@ -447,12 +443,23 @@ foo.rb
447
443
 
448
444
  END
449
445
  end
446
+
450
447
  it "-g REGEX only searches in files matching REGEX" do
451
448
  asterize_ansi(%x{rak Pikon -g f.o}).should == t=<<END
452
449
  *foo.rb*
453
450
  6|foo foo foo foo foo *Pikon* foo foo
454
451
  8|foo *Pikon* foo foo foo foo foo foo
455
452
 
453
+ END
454
+
455
+ end
456
+
457
+ it "-k REGEX only searches in files not matching REGEX" do
458
+ asterize_ansi(%x{rak Pikon -k f.o}).should == t=<<END
459
+ *dir1/bar.rb*
460
+ 2|bar bar bar bar *Pikon* bar
461
+ 9|bar bar *Pikon* bar bar bar
462
+
456
463
  END
457
464
  end
458
465
 
metadata CHANGED
@@ -1,33 +1,49 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.4
3
- specification_version: 1
4
2
  name: rak
5
3
  version: !ruby/object:Gem::Version
6
- version: "0.9"
7
- date: 2008-02-03 00:00:00 +00:00
8
- summary: A grep replacement in Ruby, type "$rak pattern".
9
- require_paths:
10
- - lib
11
- email: dan@fluentradical.com
12
- homepage: " by Daniel Lucraft"
13
- rubyforge_project: rak
14
- description: "Based on the Perl tool 'ack' by Andy Lester. Examples with similar grep: $ rak pattern $ grep pattern $(find . | grep -v .svn) $ rak --ruby pattern $ grep pattern $(find . -name '*.rb' | grep -v .svn) == FEATURES/PROBLEMS: * Ruby regular expression syntax (uses oniguruma gem if installed). * Highlighted output. * Automatically recurses down the current directory or any given directories. * Skips version control directories, backups like '~' and '#' and your * ruby project's pkg directory. * Allows inclusion and exclusion of files based on types. * Many options similar to grep."
15
- autorequire:
16
- default_executable:
17
- bindir: bin
18
- has_rdoc: true
19
- required_ruby_version: !ruby/object:Gem::Version::Requirement
20
- requirements:
21
- - - ">"
22
- - !ruby/object:Gem::Version
23
- version: 0.0.0
24
- version:
4
+ version: "1.0"
25
5
  platform: ruby
26
- signing_key:
27
- cert_chain:
28
- post_install_message:
29
6
  authors:
30
7
  - Daniel Lucraft
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-09-27 00:00:00 +01:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: hoe
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 2.3.3
24
+ version:
25
+ description: |-
26
+ Replacement for grep. Recursively scans directories to match a given
27
+ Ruby regular expression. Prints highlighted results.
28
+
29
+ Based on the Perl tool 'ack' by Andy Lester.
30
+
31
+ Examples with similar grep:
32
+
33
+ $ rak pattern
34
+ $ grep pattern $(find . | grep -v .svn)
35
+
36
+ $ rak --ruby pattern
37
+ $ grep pattern $(find . -name '*.rb' | grep -v .svn)
38
+ email: dan@fluentradical.com
39
+ executables:
40
+ - rak
41
+ extensions: []
42
+
43
+ extra_rdoc_files:
44
+ - History.txt
45
+ - Manifest.txt
46
+ - README.txt
31
47
  files:
32
48
  - History.txt
33
49
  - Manifest.txt
@@ -37,28 +53,34 @@ files:
37
53
  - lib/rak.rb
38
54
  - spec/rak_spec.rb
39
55
  - spec/help_spec.rb
40
- test_files: []
56
+ has_rdoc: true
57
+ homepage: http://rubyforge.org/projects/rak
58
+ licenses: []
41
59
 
60
+ post_install_message:
42
61
  rdoc_options:
43
62
  - --main
44
63
  - README.txt
45
- extra_rdoc_files:
46
- - History.txt
47
- - Manifest.txt
48
- - README.txt
49
- executables:
50
- - rak
51
- extensions: []
52
-
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: "0"
71
+ version:
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: "0"
77
+ version:
53
78
  requirements: []
54
79
 
55
- dependencies:
56
- - !ruby/object:Gem::Dependency
57
- name: hoe
58
- version_requirement:
59
- version_requirements: !ruby/object:Gem::Version::Requirement
60
- requirements:
61
- - - ">="
62
- - !ruby/object:Gem::Version
63
- version: 1.4.0
64
- version:
80
+ rubyforge_project: rak
81
+ rubygems_version: 1.3.4
82
+ signing_key:
83
+ specification_version: 3
84
+ summary: A grep replacement in Ruby, type "$rak pattern".
85
+ test_files: []
86
+