rak 0.8.0 → 0.9

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.
@@ -1,3 +1,14 @@
1
+
2
+ == 0.9 / 2008-02-03
3
+
4
+ * Added .rake to ruby files
5
+ * Colouring works on Win32 if win32console gem is installed.
6
+ * Checks that file is readable by the current user.
7
+ * Ignores socket files.
8
+ * Added .erb and .haml to Ruby filetypes.
9
+ * Added search at end-of/start-of line options
10
+ * Fixed searching up the directory tree when passed '.'
11
+
1
12
  == 0.8.0 / 2007-10-30
2
13
 
3
14
  * Initial release.
data/bin/rak CHANGED
@@ -1,9 +1,18 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ require 'rubygems'
4
+
5
+ if RUBY_PLATFORM =~ /mswin/
6
+ begin
7
+ require 'win32console'
8
+ rescue LoadError
9
+ ARGV << "--nocolour"
10
+ end
11
+ end
12
+
3
13
  require 'getoptlong'
4
14
 
5
15
  begin
6
- require 'rubygems'
7
16
  require 'oniguruma'
8
17
  require 'inline'
9
18
  $use_onig = true
@@ -14,7 +23,7 @@ end
14
23
  $use_onig = false
15
24
 
16
25
  class Rak
17
- VERSION = "0.0.1"
26
+ VERSION = "0.9"
18
27
 
19
28
  FILE_COLOUR = "\033[1;31m"
20
29
  MATCH_COLOUR = "\033[1;37m\033[41m"
@@ -23,7 +32,7 @@ class Rak
23
32
  VERSION_INFO=<<END
24
33
  rak #{VERSION}
25
34
 
26
- Copyright 2007 Daniel Lucraft, all rights reserved.
35
+ Copyright 2008 Daniel Lucraft, all rights reserved.
27
36
  Based on the perl tool 'ack' by Andy Lester.
28
37
 
29
38
  This program is free software; you can redistribute it and/or modify it
@@ -32,7 +41,6 @@ END
32
41
 
33
42
  FILE_TYPES = {
34
43
  :asm => %w( .s .S ),
35
- # :binary => q{Binary files, as defined by Perl's -B op (default: off)},
36
44
  :cc => %w( .c .h .xs ),
37
45
  :cpp => %w( .cpp .m .h .C .H ),
38
46
  :csharp => %w( .cs ),
@@ -41,7 +49,6 @@ END
41
49
  :haskell => %w( .hs .lhs ),
42
50
  :hh => %w( .h ),
43
51
  :html => %w( .htm .html .shtml ),
44
- # :skipped => q{Files, but not directories, normally skipped by ack (default: off)},
45
52
  :lisp => %w( .lisp ),
46
53
  :java => %w( .java properties ),
47
54
  :js => %w( .js ),
@@ -54,7 +61,7 @@ END
54
61
  :php => %w( .php .phpt .php3 .php4 .php5 ),
55
62
  :prolog => %w( .pl .ecl ),
56
63
  :python => %w( .py ),
57
- :ruby => %w( .rb .rhtml .rjs .rxml Rakefile ),
64
+ :ruby => %w( .rb .rhtml .rjs .rxml Rakefile .rake .erb .haml),
58
65
  :scheme => %w( .scm ),
59
66
  :shell => %w( .sh .bash .csh .ksh .zsh ),
60
67
  :sql => %w( .sql .ctl ),
@@ -127,7 +134,9 @@ END
127
134
  [ '--before-context', '-B', GetoptLong::REQUIRED_ARGUMENT ],
128
135
  [ '--context', '-C', GetoptLong::OPTIONAL_ARGUMENT ],
129
136
  [ '-g', GetoptLong::REQUIRED_ARGUMENT ],
130
- [ '-x', '--line-regexp', GetoptLong::NO_ARGUMENT ]
137
+ [ '-x', '--line-regexp', GetoptLong::NO_ARGUMENT ],
138
+ [ '-s', '--line-start', GetoptLong::NO_ARGUMENT ],
139
+ [ '-e', '--line-end', GetoptLong::NO_ARGUMENT ]
131
140
  )
132
141
 
133
142
  dir = nil
@@ -147,6 +156,8 @@ END
147
156
  opt[:print_match] = false
148
157
  opt[:match_whole_words] = false
149
158
  opt[:match_whole_lines] = false
159
+ opt[:match_line_starts] = false
160
+ opt[:match_line_ends] = false
150
161
  opt[:print_file_each_line] = false
151
162
  opt[:print_file_if_match] = false
152
163
  opt[:print_file_if_no_match] = false
@@ -175,7 +186,7 @@ END
175
186
  when '--help'
176
187
  if arg == ""
177
188
  puts USAGE_HELP
178
- elsif arg == "types"
189
+ elsif arg == "types" or arg == "type"
179
190
  puts TYPES_HELP
180
191
  end
181
192
  exit
@@ -282,6 +293,10 @@ END
282
293
  opt[:filename_regex] = arg
283
294
  when '-x'
284
295
  opt[:match_whole_lines] = true
296
+ when '-s'
297
+ opt[:match_line_starts] = true
298
+ when '-e'
299
+ opt[:match_line_ends] = true
285
300
  end
286
301
  end
287
302
  rescue GetoptLong::InvalidOption => ex
@@ -318,6 +333,7 @@ END
318
333
 
319
334
  def self.get_all_files(files=[], dir="./")
320
335
  Dir[dir+"*"].each do |fn|
336
+ next if fn == ".."
321
337
  if File.directory? fn
322
338
  if opt[:descend]
323
339
  if File.symlink? fn
@@ -329,12 +345,14 @@ END
329
345
  end
330
346
  end
331
347
  else
332
- if File.symlink? fn
333
- if opt[:follow_symlinks]
348
+ if !File.socket? fn and File.readable? fn
349
+ if File.symlink? fn
350
+ if opt[:follow_symlinks]
351
+ files << fn
352
+ end
353
+ else
334
354
  files << fn
335
355
  end
336
- else
337
- files << fn
338
356
  end
339
357
  end
340
358
  end
@@ -476,6 +494,12 @@ END
476
494
  if opt[:match_whole_lines]
477
495
  str = "^" + str + "$"
478
496
  end
497
+ if opt[:match_line_starts]
498
+ str = "^" + str
499
+ end
500
+ if opt[:match_line_ends]
501
+ str = str + "$"
502
+ end
479
503
  if $use_onig
480
504
  if opt[:ignore_case]
481
505
  re = Oniguruma::ORegexp.new(str, :options => Oniguruma::OPTION_IGNORECASE)
@@ -519,7 +543,7 @@ END
519
543
  code << %{ elsif fn.is_a? IO }
520
544
  code << %{ f = fn }
521
545
  code << %{ end }
522
-
546
+
523
547
  code << %{ f.each_line do |line| }
524
548
  code << %{ i += 1 }
525
549
  code << %{ rest = line }
@@ -642,9 +666,6 @@ END
642
666
  code << %{ end }
643
667
  end
644
668
  code << %{end }
645
- # if ENV['RACK_TEST'] == "true"
646
- # File.open("compiled_method.rb", "w") {|f| f.puts code}
647
- # end
648
669
  module_eval code
649
670
  end
650
671
 
@@ -692,6 +713,8 @@ Searching:
692
713
  -w, --word-regexp Force PATTERN to match only whole words
693
714
  -x, --line-regexp Force PATTERN to match only whole lines
694
715
  -Q, --literal Quote all metacharacters; expr is literal
716
+ -s, --line-start Match only at the start of a line
717
+ -e, --line-start Match only at the end of a line
695
718
 
696
719
  Search output:
697
720
  -l, --files-with-matches
@@ -780,7 +803,7 @@ Note that some extensions may appear in multiple types. For example,
780
803
  --[no]php .php .phpt .php3 .php4 .php5
781
804
  --[no]prolog .pl .ecl
782
805
  --[no]python .py
783
- --[no]ruby .rb .rhtml .rjs .rxml Rakefile
806
+ --[no]ruby .rb .rhtml .rjs .rxml Rakefile .rake .erb .haml
784
807
  --[no]scheme .scm
785
808
  --[no]shell .sh .bash .csh .ksh .zsh
786
809
  --[no]sql .sql .ctl
data/lib/rak.rb CHANGED
@@ -1,4 +1,4 @@
1
1
 
2
2
  class Rak
3
- VERSION = "0.8.0"
3
+ VERSION = "0.9"
4
4
  end
@@ -12,9 +12,9 @@ describe "Rak", "help and errors" do
12
12
 
13
13
  it "--version prints version information" do
14
14
  strip_ansi(%x{rak --version}).should == t=<<END
15
- rak 0.0.1
15
+ rak 0.9
16
16
 
17
- Copyright 2007 Daniel Lucraft, all rights reserved.
17
+ Copyright 2008 Daniel Lucraft, all rights reserved.
18
18
  Based on the perl tool 'ack' by Andy Lester.
19
19
 
20
20
  This program is free software; you can redistribute it and/or modify it
@@ -1,4 +1,5 @@
1
1
 
2
+ require 'fileutils'
2
3
 
3
4
  require File.dirname(__FILE__) + "/spec_helpers"
4
5
 
@@ -6,6 +7,9 @@ describe "Rak", "with no options" do
6
7
  before(:all) do
7
8
  ENV['RAK_TEST'] = "true"
8
9
  end
10
+ before(:each)do
11
+ FileUtils.cd(HERE+"/example/")
12
+ end
9
13
  after(:all) do
10
14
  ENV['RAK_TEST'] = "false"
11
15
  end
@@ -459,6 +463,28 @@ END
459
463
  3|*foo foo foo Caprica foo foo foo*
460
464
  4|*foo Capsicum foo foo foo foo foo*
461
465
 
466
+ END
467
+ end
468
+
469
+ it "-s means match only at the start of a line" do
470
+ asterize_ansi(%x{rak -s "foo Cap"}).should == t=<<END
471
+ *foo.rb*
472
+ 4|*foo Cap*sicum foo foo foo foo foo
473
+
474
+ END
475
+ end
476
+
477
+ it "-e means match only at the end of a line" do
478
+ asterize_ansi(%x{rak -e "kon foo foo"}).should == t=<<END
479
+ *foo.rb*
480
+ 6|foo foo foo foo foo Pi*kon foo foo*
481
+
482
+ END
483
+ end
484
+
485
+ it "should not recurse down '..' when used with . " do
486
+ FileUtils.cd(HERE+"/example/dir1/")
487
+ asterize_ansi(%x{rak foo .}).should == t=<<END
462
488
  END
463
489
  end
464
490
  end
@@ -467,6 +493,9 @@ describe "Rak", "with combinations of options" do
467
493
  before(:all) do
468
494
  ENV['RAK_TEST'] = "true"
469
495
  end
496
+ before(:each)do
497
+ FileUtils.cd(HERE+"/example/")
498
+ end
470
499
  after(:all) do
471
500
  ENV['RAK_TEST'] = "false"
472
501
  end
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: rak
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.8.0
7
- date: 2007-11-02 00:00:00 +00:00
6
+ version: "0.9"
7
+ date: 2008-02-03 00:00:00 +00:00
8
8
  summary: A grep replacement in Ruby, type "$rak pattern".
9
9
  require_paths:
10
10
  - lib
@@ -60,5 +60,5 @@ dependencies:
60
60
  requirements:
61
61
  - - ">="
62
62
  - !ruby/object:Gem::Version
63
- version: 1.3.0
63
+ version: 1.4.0
64
64
  version: