grepmate 2.0.5
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.
- data/.gitignore +1 -0
- data/LICENSE +20 -0
- data/README.rdoc +60 -0
- data/Rakefile +52 -0
- data/VERSION +1 -0
- data/bin/grepmate +86 -0
- data/config/dot-grepmate +53 -0
- data/grepmate.gemspec +66 -0
- data/lib/.empty +0 -0
- data/lib/.git-empty +1 -0
- data/lib/grepmate.rb +188 -0
- data/lib/output/file_and_line.rb +17 -0
- data/lib/output/html.rb +136 -0
- data/lib/output/text.rb +11 -0
- data/lib/output/textmate.rb +22 -0
- data/spec/grepmate_spec.rb +117 -0
- data/spec/spec_helper.rb +11 -0
- data/tmp/grepmate.html +83 -0
- metadata +94 -0
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
pkg
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Steven Soroka
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
= Grepmate
|
2
|
+
|
3
|
+
Extremely fast search of rails projects or ruby source for code.
|
4
|
+
|
5
|
+
Supports opening search results in textmate, browser (html), or as text.
|
6
|
+
|
7
|
+
== Usage
|
8
|
+
|
9
|
+
NAME
|
10
|
+
grepmate
|
11
|
+
|
12
|
+
SYNOPSIS
|
13
|
+
grepmate [what_to_search_for*] [dir=dir] [options]+
|
14
|
+
|
15
|
+
PARAMETERS
|
16
|
+
what_to_search_for (-1 ~> what_to_search_for)
|
17
|
+
Search terms. Enclose in quotes to search for phrase. use with -e or
|
18
|
+
--regex option for regular expression support
|
19
|
+
dir=dir (-1 ~> dir)
|
20
|
+
Directories to search. Defaults to project dirs.
|
21
|
+
--case
|
22
|
+
Case sensitive search (default is off).
|
23
|
+
--textmate, -t
|
24
|
+
open matches in textmate
|
25
|
+
--html
|
26
|
+
Turn on html output (default)
|
27
|
+
--text
|
28
|
+
show matches as text, file and line number
|
29
|
+
--file_and_line, -f
|
30
|
+
output only match file and line number
|
31
|
+
--rails, -r
|
32
|
+
Search Rails source, in addition to whatever is named by dir parameter
|
33
|
+
etc.
|
34
|
+
--only_rails, -R
|
35
|
+
Search only Rails source, not the project. Takes precedence over dir
|
36
|
+
parameter
|
37
|
+
--gems, -g
|
38
|
+
Search all gems, in addition to whatever is named by dir parameter
|
39
|
+
etc.
|
40
|
+
--only_gems, -G
|
41
|
+
Search only gems, not the project. Takes precedence over dir parameter
|
42
|
+
--wait, -w
|
43
|
+
Wait between finds until TextMate file is closed. Only works with
|
44
|
+
textmate output (--textmate or -t).
|
45
|
+
--count, -c
|
46
|
+
Display only the number of matches.
|
47
|
+
--regex, -e
|
48
|
+
use regular expression search terms
|
49
|
+
--verbose, -v
|
50
|
+
Turn on verbose mode and explain everything
|
51
|
+
--help, -h
|
52
|
+
|
53
|
+
== Authors
|
54
|
+
|
55
|
+
- Steven Soroka
|
56
|
+
- Zach Holt
|
57
|
+
|
58
|
+
== To Do
|
59
|
+
|
60
|
+
- check ~/.grepmate for current rails repo to use instead of always using latest
|
data/Rakefile
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "grepmate"
|
8
|
+
gem.summary = %Q{Extremely fast search of rails projects or rails source for code, open in textmate or browser with html output}
|
9
|
+
gem.description = gem.summary
|
10
|
+
gem.email = "ssoroka78@gmail.com"
|
11
|
+
gem.homepage = "http://github.com/ssoroka/grepmate"
|
12
|
+
gem.authors = ["Steven Soroka", 'Zach Holt']
|
13
|
+
gem.add_dependency 'main', '>= 2.8.3'
|
14
|
+
gem.add_dependency 'syntax', '>= 1.0.0'
|
15
|
+
gem.executables = ['grepmate']
|
16
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
17
|
+
end
|
18
|
+
|
19
|
+
rescue LoadError
|
20
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
21
|
+
end
|
22
|
+
|
23
|
+
require 'spec/rake/spectask'
|
24
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
25
|
+
spec.libs << 'lib' << 'spec'
|
26
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
27
|
+
end
|
28
|
+
|
29
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
30
|
+
spec.libs << 'lib' << 'spec'
|
31
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
32
|
+
spec.rcov = true
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
task :default => :spec
|
37
|
+
|
38
|
+
require 'rake/rdoctask'
|
39
|
+
Rake::RDocTask.new do |rdoc|
|
40
|
+
if File.exist?('VERSION.yml')
|
41
|
+
config = YAML.load(File.read('VERSION.yml'))
|
42
|
+
version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
|
43
|
+
else
|
44
|
+
version = ""
|
45
|
+
end
|
46
|
+
|
47
|
+
rdoc.rdoc_dir = 'rdoc'
|
48
|
+
rdoc.title = "grepmate #{version}"
|
49
|
+
rdoc.rdoc_files.include('README*')
|
50
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
51
|
+
end
|
52
|
+
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.0.5
|
data/bin/grepmate
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'rubygems'
|
3
|
+
gem 'main', '>=2.8.0'
|
4
|
+
require 'main'
|
5
|
+
require File.join(File.dirname(__FILE__), %w(.. lib grepmate))
|
6
|
+
|
7
|
+
Main {
|
8
|
+
option('case') {
|
9
|
+
cast :bool
|
10
|
+
description 'Case sensitive search (default is off).'
|
11
|
+
}
|
12
|
+
|
13
|
+
option('textmate', 't') {
|
14
|
+
cast :bool
|
15
|
+
description 'open matches in textmate'
|
16
|
+
}
|
17
|
+
|
18
|
+
option('html') {
|
19
|
+
cast :bool
|
20
|
+
description 'Turn on html output (default)'
|
21
|
+
}
|
22
|
+
|
23
|
+
option('text') {
|
24
|
+
cast :bool
|
25
|
+
description 'show matches as text, file and line number'
|
26
|
+
}
|
27
|
+
|
28
|
+
option('file_and_line', 'f') {
|
29
|
+
cast :bool
|
30
|
+
description 'output only match file and line number'
|
31
|
+
}
|
32
|
+
|
33
|
+
option('rails', 'r') {
|
34
|
+
cast :bool
|
35
|
+
description 'Search Rails source, in addition to whatever is named by dir parameter etc.'
|
36
|
+
}
|
37
|
+
|
38
|
+
option('only_rails', 'R') {
|
39
|
+
cast :bool
|
40
|
+
description 'Search only Rails source, not the project. Takes precedence over dir parameter'
|
41
|
+
}
|
42
|
+
|
43
|
+
option('gems', 'g') {
|
44
|
+
cast :bool
|
45
|
+
description "Search all gems, in addition to whatever is named by dir parameter etc."
|
46
|
+
}
|
47
|
+
|
48
|
+
option('only_gems', 'G') {
|
49
|
+
cast :bool
|
50
|
+
description "Search only gems, not the project. Takes precedence over dir parameter"
|
51
|
+
}
|
52
|
+
|
53
|
+
option('wait', 'w') {
|
54
|
+
cast :bool
|
55
|
+
description 'Wait between finds until TextMate file is closed. Only works with textmate output (--textmate or -t).'
|
56
|
+
}
|
57
|
+
|
58
|
+
option('count', 'c') {
|
59
|
+
cast :bool
|
60
|
+
description 'Display only the number of matches.'
|
61
|
+
}
|
62
|
+
|
63
|
+
option('regex', 'e') {
|
64
|
+
description 'use regular expression search terms'
|
65
|
+
}
|
66
|
+
|
67
|
+
option('verbose', 'v') {
|
68
|
+
description 'Turn on verbose mode and explain everything'
|
69
|
+
}
|
70
|
+
|
71
|
+
keyword('dir', 'd') {
|
72
|
+
arity -1
|
73
|
+
description 'Directories to search. Defaults to project dirs.'
|
74
|
+
}
|
75
|
+
|
76
|
+
argument('what_to_search_for') {
|
77
|
+
arity -1
|
78
|
+
description "Search terms. Enclose in quotes to search for phrase. use with -e or --regex option for regular expression support"
|
79
|
+
}
|
80
|
+
|
81
|
+
def run
|
82
|
+
grepmate = Grepmate.new(params)
|
83
|
+
grepmate.find
|
84
|
+
grepmate.display
|
85
|
+
end
|
86
|
+
}
|
data/config/dot-grepmate
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# this file will be installed as ~/.grepmate
|
2
|
+
---
|
3
|
+
# valid outputs are: text, html, textmate, file_and_line
|
4
|
+
default_output: html
|
5
|
+
temp_directory: <%= ENV['TMPDIR'] %>
|
6
|
+
search_rails_source: false
|
7
|
+
search_gems: false
|
8
|
+
# if you only want to search a specific rails version, uncomment and set this:
|
9
|
+
# :use_only_rails_version: 2.3.2
|
10
|
+
exclude_file_extensions:
|
11
|
+
- sql
|
12
|
+
- log
|
13
|
+
- tmp
|
14
|
+
- gz
|
15
|
+
- bz2
|
16
|
+
- tar
|
17
|
+
- zip
|
18
|
+
- db
|
19
|
+
- sqlite
|
20
|
+
- sqlite3
|
21
|
+
- csv
|
22
|
+
- DS_Store
|
23
|
+
- svn
|
24
|
+
- git
|
25
|
+
- tmproj
|
26
|
+
- sql
|
27
|
+
- dat
|
28
|
+
- gitignore
|
29
|
+
- gitmodules
|
30
|
+
- gemspec
|
31
|
+
- rdoc
|
32
|
+
- ico
|
33
|
+
- pdf
|
34
|
+
- xml
|
35
|
+
- html
|
36
|
+
- swf
|
37
|
+
- jpg
|
38
|
+
- png
|
39
|
+
- gif
|
40
|
+
include_dirs:
|
41
|
+
- .
|
42
|
+
exclude_dirs:
|
43
|
+
- .git
|
44
|
+
- .svn
|
45
|
+
- sphinx
|
46
|
+
- sql
|
47
|
+
- tmp
|
48
|
+
- log
|
49
|
+
- doc
|
50
|
+
- coverage
|
51
|
+
- flash
|
52
|
+
- images
|
53
|
+
- videos
|
data/grepmate.gemspec
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{grepmate}
|
8
|
+
s.version = "2.0.5"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Steven Soroka", "Zach Holt"]
|
12
|
+
s.date = %q{2009-10-16}
|
13
|
+
s.default_executable = %q{grepmate}
|
14
|
+
s.description = %q{Extremely fast search of rails projects or rails source for code, open in textmate or browser with html output}
|
15
|
+
s.email = %q{ssoroka78@gmail.com}
|
16
|
+
s.executables = ["grepmate"]
|
17
|
+
s.extra_rdoc_files = [
|
18
|
+
"LICENSE",
|
19
|
+
"README.rdoc"
|
20
|
+
]
|
21
|
+
s.files = [
|
22
|
+
".gitignore",
|
23
|
+
"LICENSE",
|
24
|
+
"README.rdoc",
|
25
|
+
"Rakefile",
|
26
|
+
"VERSION",
|
27
|
+
"bin/grepmate",
|
28
|
+
"config/dot-grepmate",
|
29
|
+
"grepmate.gemspec",
|
30
|
+
"lib/.empty",
|
31
|
+
"lib/.git-empty",
|
32
|
+
"lib/grepmate.rb",
|
33
|
+
"lib/output/file_and_line.rb",
|
34
|
+
"lib/output/html.rb",
|
35
|
+
"lib/output/text.rb",
|
36
|
+
"lib/output/textmate.rb",
|
37
|
+
"spec/grepmate_spec.rb",
|
38
|
+
"spec/spec_helper.rb",
|
39
|
+
"tmp/grepmate.html"
|
40
|
+
]
|
41
|
+
s.homepage = %q{http://github.com/ssoroka/grepmate}
|
42
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
43
|
+
s.require_paths = ["lib"]
|
44
|
+
s.rubygems_version = %q{1.3.5}
|
45
|
+
s.summary = %q{Extremely fast search of rails projects or rails source for code, open in textmate or browser with html output}
|
46
|
+
s.test_files = [
|
47
|
+
"spec/grepmate_spec.rb",
|
48
|
+
"spec/spec_helper.rb"
|
49
|
+
]
|
50
|
+
|
51
|
+
if s.respond_to? :specification_version then
|
52
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
53
|
+
s.specification_version = 3
|
54
|
+
|
55
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
56
|
+
s.add_runtime_dependency(%q<main>, [">= 2.8.3"])
|
57
|
+
s.add_runtime_dependency(%q<syntax>, [">= 1.0.0"])
|
58
|
+
else
|
59
|
+
s.add_dependency(%q<main>, [">= 2.8.3"])
|
60
|
+
s.add_dependency(%q<syntax>, [">= 1.0.0"])
|
61
|
+
end
|
62
|
+
else
|
63
|
+
s.add_dependency(%q<main>, [">= 2.8.3"])
|
64
|
+
s.add_dependency(%q<syntax>, [">= 1.0.0"])
|
65
|
+
end
|
66
|
+
end
|
data/lib/.empty
ADDED
File without changes
|
data/lib/.git-empty
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
|
data/lib/grepmate.rb
ADDED
@@ -0,0 +1,188 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
begin
|
3
|
+
gem 'syntax'
|
4
|
+
rescue LoadError
|
5
|
+
end
|
6
|
+
require 'yaml'
|
7
|
+
require 'erb'
|
8
|
+
require 'enumerator'
|
9
|
+
require File.join(File.dirname(__FILE__), 'output', 'html')
|
10
|
+
require File.join(File.dirname(__FILE__), 'output', 'textmate')
|
11
|
+
require File.join(File.dirname(__FILE__), 'output', 'text')
|
12
|
+
require File.join(File.dirname(__FILE__), 'output', 'file_and_line')
|
13
|
+
|
14
|
+
class Grepmate
|
15
|
+
attr_reader :params, :dirs, :query, :results, :config
|
16
|
+
CONFIG_FILE = File.expand_path("~/.grepmate")
|
17
|
+
|
18
|
+
def initialize(params)
|
19
|
+
@params = params
|
20
|
+
|
21
|
+
load_config
|
22
|
+
end
|
23
|
+
|
24
|
+
def gem_path
|
25
|
+
`gem environment gemdir`.chomp
|
26
|
+
end
|
27
|
+
|
28
|
+
def gems_path
|
29
|
+
File.join(gem_path, 'gems')
|
30
|
+
end
|
31
|
+
|
32
|
+
def rails_version
|
33
|
+
`rails -v`.chomp.split(' ').last
|
34
|
+
end
|
35
|
+
|
36
|
+
def rails_path
|
37
|
+
vendor_rails = "vendor/rails"
|
38
|
+
|
39
|
+
if File.exist?(vendor_rails)
|
40
|
+
vendor_rails
|
41
|
+
else
|
42
|
+
Dir["#{gems_path}/acti*-#{rails_version}"]
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def load_config
|
47
|
+
if !File.exist?(CONFIG_FILE)
|
48
|
+
# create
|
49
|
+
safe_puts "Creating config file #{CONFIG_FILE}..."
|
50
|
+
FileUtils.cp(File.expand_path(File.join(File.dirname(__FILE__), %w(.. config dot-grepmate))), CONFIG_FILE)
|
51
|
+
else
|
52
|
+
verbose("Using config file #{CONFIG_FILE}...")
|
53
|
+
end
|
54
|
+
|
55
|
+
# load
|
56
|
+
@config = YAML::load(ERB.new(File.read(CONFIG_FILE)).result)
|
57
|
+
# set output type
|
58
|
+
@output = @config['default_output']
|
59
|
+
%w(html text textmate file_and_line).each{|out_type|
|
60
|
+
@output = out_type if params[out_type].value
|
61
|
+
}
|
62
|
+
verbose("Output mode set to #{@output}")
|
63
|
+
|
64
|
+
# set default search directories
|
65
|
+
unless params['dir'].values.any?
|
66
|
+
params['dir'].values = @config['include_dirs']
|
67
|
+
end
|
68
|
+
|
69
|
+
# exclude extensions
|
70
|
+
@exclude_exts = (@config['exclude_file_extensions'] || [])
|
71
|
+
verbose "Excluding file extensions: #{@exclude_exts.join(' ')}"
|
72
|
+
# dir exclusions
|
73
|
+
@exclude_dirs = (@config['exclude_dirs'] || [])
|
74
|
+
verbose "Excluding dirs: #{@exclude_dirs.join(' ')}"
|
75
|
+
|
76
|
+
@search_rails = params['rails'].given? ? params['rails'].value : @config['search_rails_source']
|
77
|
+
verbose "Searching rails source" if @search_rails
|
78
|
+
@search_gems = params['gems'].given? ? params['gems'].value : @config['search_gems']
|
79
|
+
verbose "Searching gems source" if @search_gems
|
80
|
+
end
|
81
|
+
|
82
|
+
# use default dirs, param dirs, or files/dirs from STDIN
|
83
|
+
def determine_directories_to_search
|
84
|
+
if STDIN.tty?
|
85
|
+
@dirs = if params['only_rails'].value || params['only_gems'].value
|
86
|
+
[]
|
87
|
+
else
|
88
|
+
params['dir'].values || []
|
89
|
+
end
|
90
|
+
@dirs += Array(rails_path) if params['only_rails'].value || params['rails'].value
|
91
|
+
@dirs << gems_path if params['only_gems'].value || params['gems'].value
|
92
|
+
else
|
93
|
+
@dirs = []
|
94
|
+
input = STDIN.read
|
95
|
+
|
96
|
+
input.split("\n").each do |ln|
|
97
|
+
if ln =~ /^([^:]*)/ # Assume everything to the first colon is a file name
|
98
|
+
# filename = File.expand_path($1)
|
99
|
+
# if File.exist?(filename) # But actually check that it is
|
100
|
+
@dirs << $1# filename
|
101
|
+
# end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
@dirs.uniq! # remove duplicates
|
106
|
+
verbose "including dirs: #{@dirs.join(' ')}"
|
107
|
+
@dirs.reject!{ |dir|
|
108
|
+
!File.exist?(dir) || @exclude_dirs.any?{ |exclude| dir =~ /(^|\/)#{exclude}(\/|$)/i }
|
109
|
+
}
|
110
|
+
verbose "rejected dirs, left with: #{@dirs.join(' ')}"
|
111
|
+
end
|
112
|
+
|
113
|
+
def determine_what_to_search_for
|
114
|
+
# funny bunny => 'funny' 'bunny'
|
115
|
+
# 'funny bunny' => 'funny bunny'
|
116
|
+
if params['regex'].value
|
117
|
+
exp = params['what_to_search_for'].value.dup
|
118
|
+
exp.gsub!(/^\//, '')
|
119
|
+
exp.gsub!(/\/$/, '')
|
120
|
+
@query = %("#{exp}")
|
121
|
+
verbose "Searching for: /#{exp}/"
|
122
|
+
else
|
123
|
+
verbose "Searching for: #{params['what_to_search_for'].values.inspect}"
|
124
|
+
@query = params['what_to_search_for'].values.map {|v| "\"#{v.gsub(/"/, '\\"')}\"" }.join(" ")
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
def find
|
129
|
+
determine_directories_to_search
|
130
|
+
determine_what_to_search_for
|
131
|
+
|
132
|
+
@results = []
|
133
|
+
if @dirs.any?
|
134
|
+
paths = `find #{@dirs.join(' ')}`.split("\n").map{|sp| sp.gsub(' ', '\\ ')} # escape spaces in found files
|
135
|
+
paths = paths.map!{|p| p.gsub(/^\.\//, '') }.uniq
|
136
|
+
paths.reject! { |path|
|
137
|
+
@exclude_exts.any?{ |exclude| path =~ /\.#{Regexp.escape(exclude)}$/i } ||
|
138
|
+
@exclude_dirs.any?{ |exclude| path =~ /(^|\/)#{Regexp.escape(exclude)}(\/|$)/i }
|
139
|
+
}
|
140
|
+
|
141
|
+
cmd = 'grep '
|
142
|
+
cmd << '-i ' unless params['case'].value
|
143
|
+
# 3 lines of context for html and text
|
144
|
+
cmd << '-C 3 ' if (@output == 'html') && !params['count'].value
|
145
|
+
cmd << '-E ' if params['regex']
|
146
|
+
|
147
|
+
# paths get too large for grep to handle, so limit the number it has to deal with at once.
|
148
|
+
paths.each_slice(100) {|sub_paths|
|
149
|
+
@results += `#{cmd} -n #{query} #{sub_paths.join(' ')}`.split("\n")
|
150
|
+
}
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
def display
|
155
|
+
if @results.empty?
|
156
|
+
safe_puts "Nothing found!"
|
157
|
+
exit
|
158
|
+
elsif params['count'].value
|
159
|
+
puts "Matches: #{@results.size}"
|
160
|
+
exit
|
161
|
+
end
|
162
|
+
|
163
|
+
output_class = case @output.to_s
|
164
|
+
when 'html'
|
165
|
+
Output::HTML
|
166
|
+
when 'text'
|
167
|
+
Output::Text
|
168
|
+
when 'textmate'
|
169
|
+
Output::Textmate
|
170
|
+
when 'file_and_line'
|
171
|
+
Output::FileAndLine
|
172
|
+
end
|
173
|
+
|
174
|
+
output_class.new(self).process
|
175
|
+
end
|
176
|
+
|
177
|
+
def safe_puts(msg)
|
178
|
+
if STDOUT.tty?
|
179
|
+
puts msg
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
def verbose(msg)
|
184
|
+
if @params['verbose'].value
|
185
|
+
puts msg
|
186
|
+
end
|
187
|
+
end
|
188
|
+
end
|
data/lib/output/html.rb
ADDED
@@ -0,0 +1,136 @@
|
|
1
|
+
module Output
|
2
|
+
class HTML
|
3
|
+
def initialize(grepmate)
|
4
|
+
@grepmate = grepmate
|
5
|
+
temp_dir = grepmate.config['temp_directory'] || ENV['TMPDIR']
|
6
|
+
@temp_file = File.expand_path(File.join(temp_dir, %w(grepmate.html)))
|
7
|
+
end
|
8
|
+
|
9
|
+
def determine_javascript_highlight_text
|
10
|
+
@grepmate.params['what_to_search_for'].values.map {|v| "highlightSearchTerms('#{v.gsub(/'/, "\\'").gsub(/:/, "\\:")}', false)" }.join(";")
|
11
|
+
end
|
12
|
+
|
13
|
+
def process
|
14
|
+
syntax_installed = true
|
15
|
+
begin
|
16
|
+
require 'syntax/convertors/html'
|
17
|
+
rescue LoadError
|
18
|
+
syntax_installed = false
|
19
|
+
end
|
20
|
+
|
21
|
+
html = '<html><head>'
|
22
|
+
html << <<-CSS
|
23
|
+
<style type="text/css">body { background-color: #EEEEEE; } pre {
|
24
|
+
display: inline; } .ruby { font-family: Monaco; font-size: 10pt;
|
25
|
+
background-color: white } .ruby .normal {} .ruby .comment { color:
|
26
|
+
#005; font-style: italic; } .ruby .keyword { color: #A00; font-weight:
|
27
|
+
bold; } .ruby .method { color: #077; } .ruby .class { color: #074; }
|
28
|
+
.ruby .module { color: #050; } .ruby .punct { color: #447; font-weight:
|
29
|
+
bold; } .ruby .symbol { color: #099; } .ruby .string { color: #944;
|
30
|
+
background: #FFE; } .ruby .char { color: #F07; } .ruby .ident { color:
|
31
|
+
#004; } .ruby .constant { color: #07F; } .ruby .regex { color: #B66;
|
32
|
+
background: #FEF; } .ruby .number { color: #F99; } .ruby .attribute {
|
33
|
+
color: #7BB; } .ruby .global { color: #7FB; } .ruby .expr { color:
|
34
|
+
#227; } .ruby .escape { color: #277; } .ruby .highlight {
|
35
|
+
background-color: yellow; font-weight: 900; } td.lineno { text-align:
|
36
|
+
right; font-family: Monaco; font-size: 9pt; padding-right: 10px; }
|
37
|
+
td.filename { padding-top: 35px; font-family: Monaco; font-size: 14pt;
|
38
|
+
}</style>
|
39
|
+
|
40
|
+
<script type="text/javascript">
|
41
|
+
// http://www.nsftools.com/misc/SearchAndHighlight.htm
|
42
|
+
|
43
|
+
function doHighlight(bodyText,searchTerm,highlightStartTag,highlightEndTag)
|
44
|
+
{if((!highlightStartTag)||(!highlightEndTag)){highlightStartTag="<font style='color:blue; background-color:yellow;'>";highlightEndTag="</font>";}
|
45
|
+
var newText="";var i=-1;var lcSearchTerm=searchTerm.toLowerCase();var lcBodyText=bodyText.toLowerCase();while(bodyText.length>0){i=lcBodyText.indexOf(lcSearchTerm,i+1);if(i<0){newText+=bodyText;bodyText="";}else{if(bodyText.lastIndexOf(">",i)>=bodyText.lastIndexOf("<",i)){if(lcBodyText.lastIndexOf("/script>",i)>=lcBodyText.lastIndexOf("<script",i)){newText+=bodyText.substring(0,i)+highlightStartTag+bodyText.substr(i,searchTerm.length)+highlightEndTag;bodyText=bodyText.substr(i+searchTerm.length);lcBodyText=bodyText.toLowerCase();i=-1;}}}}
|
46
|
+
return newText;}
|
47
|
+
function highlightSearchTerms(searchText,treatAsPhrase,warnOnFailure,highlightStartTag,highlightEndTag)
|
48
|
+
{if(treatAsPhrase){searchArray=[searchText];}else{searchArray=searchText.split(" ");}
|
49
|
+
if(!document.body||typeof(document.body.innerHTML)=="undefined"){if(warnOnFailure){alert("Sorry, for some reason the text of this page is unavailable. Searching will not work.");}
|
50
|
+
return false;}
|
51
|
+
var bodyText=document.body.innerHTML;for(var i=0;i<searchArray.length;i++){bodyText=doHighlight(bodyText,searchArray[i],highlightStartTag,highlightEndTag);}
|
52
|
+
document.body.innerHTML=bodyText;return true;}</script></script>
|
53
|
+
CSS
|
54
|
+
|
55
|
+
# some searches can return stupid-huge result sets. Javascript will likely freeze or crash the browser in those cases.
|
56
|
+
if @grepmate.results.size < 1000
|
57
|
+
html << "</head><body onLoad=\"#{determine_javascript_highlight_text}\">"
|
58
|
+
else
|
59
|
+
html << "</head><body>"
|
60
|
+
end
|
61
|
+
|
62
|
+
syntax_converter = (syntax_installed ? Syntax::Convertors::HTML.for_syntax("ruby") : nil)
|
63
|
+
html << '<pre>sudo gem install syntax</pre> to get syntax highlighting<br><br>' unless syntax_installed
|
64
|
+
|
65
|
+
html << '<table cellspacing="0" cellpadding="2">'
|
66
|
+
|
67
|
+
last_file = ''
|
68
|
+
separator = false
|
69
|
+
|
70
|
+
html << @grepmate.results.map{ |line|
|
71
|
+
if line == '--'
|
72
|
+
separator = true
|
73
|
+
''
|
74
|
+
elsif line =~ /^(.+?)-(\d+)-(.*)$/ || line =~ /^(.+?):(\d+):(.*)$/
|
75
|
+
file = File.expand_path($1)
|
76
|
+
line = $2
|
77
|
+
context = $3
|
78
|
+
|
79
|
+
file_group = ''
|
80
|
+
|
81
|
+
if file == last_file
|
82
|
+
file_group << "<tr><td class=\"lineno\">...</td><td></td></tr>" if separator
|
83
|
+
else
|
84
|
+
parts = file.split(/\//)
|
85
|
+
path = ''
|
86
|
+
file_group << "<tr><td colspan=\"2\" class=\"filename\">"
|
87
|
+
parts.each do |part|
|
88
|
+
path << "/#{part}"
|
89
|
+
file_group << "/" unless part.equal?(parts.first)
|
90
|
+
if part.equal?(parts.last)
|
91
|
+
file_group << "<a href=\"txmt://open?url=file://#{file}\">#{part}</a>"
|
92
|
+
else
|
93
|
+
file_group << "<a href=\"file:/#{path}\">#{part}</a>"
|
94
|
+
end
|
95
|
+
end
|
96
|
+
file_group << "</td></tr>\n"
|
97
|
+
end
|
98
|
+
|
99
|
+
separator = false
|
100
|
+
last_file = file
|
101
|
+
|
102
|
+
file_group << "<tr><td class=\"lineno\"><a href=\"txmt://open?url=file://#{file}&line=#{line}\">#{line}</a></td>"
|
103
|
+
|
104
|
+
converted = begin
|
105
|
+
syntax_converter ? syntax_converter.convert(context =~ /^(.+?)\s*$/ ? $1 : context) : context
|
106
|
+
rescue Exception => e
|
107
|
+
"TOKENIZING ERROR: #{context} <!-- \n#{e.message}\n#{e.backtrace.join("\n")}\n -->"
|
108
|
+
end
|
109
|
+
file_group << "<td class=\"ruby\">#{converted}</td></tr>\n"
|
110
|
+
|
111
|
+
file_group
|
112
|
+
end
|
113
|
+
}.join
|
114
|
+
|
115
|
+
html << '</table></body></html>'
|
116
|
+
|
117
|
+
begin
|
118
|
+
FileUtils.touch(@temp_file)
|
119
|
+
rescue Errno::EACCES => e
|
120
|
+
puts %(
|
121
|
+
|
122
|
+
Looks like there's a permission error for the file #{@temp_file}. The grepmate gem expects to have write access to this file.
|
123
|
+
|
124
|
+
To fix, please do:
|
125
|
+
sudo chmod 0666 #{@temp_file}
|
126
|
+
|
127
|
+
)
|
128
|
+
raise e
|
129
|
+
end
|
130
|
+
File.open(@temp_file, 'w') { |f| f.write(html) }
|
131
|
+
|
132
|
+
system("open #{@temp_file}")
|
133
|
+
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
data/lib/output/text.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
module Output
|
2
|
+
class Textmate
|
3
|
+
def initialize(grepmate)
|
4
|
+
@grepmate = grepmate
|
5
|
+
end
|
6
|
+
|
7
|
+
def process
|
8
|
+
print "Found #{@grepmate.results.size} matches. "
|
9
|
+
if @grepmate.results.size > 20
|
10
|
+
puts "Display? [Y/n]..."
|
11
|
+
exit if $stdin.gets.chomp.downcase == 'n'
|
12
|
+
else
|
13
|
+
puts ''
|
14
|
+
end
|
15
|
+
|
16
|
+
@grepmate.results.each { |f|
|
17
|
+
file, line = f.split(':')
|
18
|
+
system("mate #{'-w ' if @grepmate.params['wait'].value}-l #{line} #{file}")
|
19
|
+
}
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,117 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "Grepmate" do
|
4
|
+
before(:each) do
|
5
|
+
@orig_pwd = Dir.pwd
|
6
|
+
Dir.chdir(File.expand_path(File.join(File.dirname(__FILE__), '..')))
|
7
|
+
end
|
8
|
+
|
9
|
+
after(:each) do
|
10
|
+
# change back
|
11
|
+
Dir.chdir @orig_pwd
|
12
|
+
end
|
13
|
+
|
14
|
+
describe 'bin/grepmate' do
|
15
|
+
it "should search project" do
|
16
|
+
output = `bin/grepmate -c "module Output"`.split("\n").compact.last
|
17
|
+
output.should =~ /Matches\: (\d+)/
|
18
|
+
output.scan(/Matches\: (\d+)/).flatten.first.to_i.should >= 6
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should behave when piped STDIN files" do
|
22
|
+
`echo LICENSE | bin/grepmate -c "Steven Soroka"`.chomp.should == 'Matches: 1'
|
23
|
+
end
|
24
|
+
#
|
25
|
+
# it "should search gems" do
|
26
|
+
# # dev most likely has "main" gem installed, since it's a requirement, search for the words "gem install main" in the readme.
|
27
|
+
# `bin/grepmate -G -f "gem install main" 2> /dev/null`.grep(/main-[\d\.]+\/README/).should_not be_nil
|
28
|
+
# end
|
29
|
+
#
|
30
|
+
# it "should search rails" do
|
31
|
+
# # changelog is unlikely to change or go missing, since it's historical.
|
32
|
+
# `bin/grepmate -R -f "Fixed that validate_length_of lost :on option when :within was specified" 2> /dev/null`.grep(/CHANGELOG/).should_not be_nil
|
33
|
+
# end
|
34
|
+
|
35
|
+
it "should support regular expressions" do
|
36
|
+
# from LICENSE: this will match: Steven Soroka
|
37
|
+
`echo LICENSE | bin/grepmate -c -e "even .oro.a"`.chomp.should == 'Matches: 1'
|
38
|
+
end
|
39
|
+
|
40
|
+
describe 'output' do
|
41
|
+
it "should output text" do
|
42
|
+
result = `bin/grepmate --text 'Steven Soroka'`
|
43
|
+
# spec/grepmate_spec.rb:22: `echo LICENSE | bin/grepmate -c "Steven Soroka"`.chomp.should == 'Matches: 1'
|
44
|
+
# spec/grepmate_spec.rb:36: # from LICENSE: this will match: Steven Soroka
|
45
|
+
# spec/grepmate_spec.rb:42: puts `bin/grepmate --text 'Steven Soroka'`
|
46
|
+
# spec/grepmate_spec.rb:46: # `bin/grepmate --html 'Steven Soroka'`
|
47
|
+
# spec/grepmate_spec.rb:61: params.(blah blah blah blah blah blah blah blah blah blah)s => ["Steven Soroka"]))
|
48
|
+
result.should =~ /grepmate_spec/
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should output html" do
|
52
|
+
# `bin/grepmate --html 'Steven Soroka'`
|
53
|
+
params = mock(:params)
|
54
|
+
params.should_receive(:[]).with('html').any_number_of_times.and_return(mock(:html, :value => true))
|
55
|
+
params.should_receive(:[]).with('text').any_number_of_times.and_return(mock(:text, :value => false))
|
56
|
+
params.should_receive(:[]).with('textmate').any_number_of_times.and_return(mock(:textmate, :value => false))
|
57
|
+
params.should_receive(:[]).with('file_and_line').any_number_of_times.and_return(mock(:file_and_line, :value => false))
|
58
|
+
params.should_receive(:[]).with('dir').any_number_of_times.and_return(mock(:dir, :values => ['bin', 'config', 'lib', 'spec'], :values= => nil))
|
59
|
+
params.should_receive(:[]).with('rails').any_number_of_times.and_return(mock(:rails, :given? => nil, :value => nil))
|
60
|
+
params.should_receive(:[]).with('gems').any_number_of_times.and_return(mock(:gems, :given? => nil, :value => nil))
|
61
|
+
params.should_receive(:[]).with('only_rails').any_number_of_times.and_return(mock(:only_rails, :value => nil))
|
62
|
+
params.should_receive(:[]).with('only_gems').any_number_of_times.and_return(mock(:only_gems, :value => nil))
|
63
|
+
params.should_receive(:[]).with('regex').any_number_of_times.and_return(mock(:regex, :value => nil))
|
64
|
+
params.should_receive(:[]).with('case').any_number_of_times.and_return(mock(:case, :value => nil))
|
65
|
+
params.should_receive(:[]).with('count').any_number_of_times.and_return(mock(:count, :value => nil))
|
66
|
+
params.should_receive(:[]).with('verbose').any_number_of_times.and_return(mock(:verbose, :value => nil))
|
67
|
+
params.should_receive(:[]).with('what_to_search_for').any_number_of_times.and_return(mock(:what_to_search_for, :values => ["Steven Soroka"]))
|
68
|
+
|
69
|
+
grepmate = Grepmate.new(params)
|
70
|
+
# hijack the output class so that it doesn't send the system() call.
|
71
|
+
output_class = Output::HTML.new(grepmate)
|
72
|
+
output_class.should_receive(:system).with("open #{output_class.instance_variable_get('@temp_file')}")
|
73
|
+
|
74
|
+
Output::HTML.stub!(:new).and_return(output_class)
|
75
|
+
|
76
|
+
grepmate.find
|
77
|
+
grepmate.display
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should output textmate commands" do
|
81
|
+
# `bin/grepmate --textmate 'Steven Soroka'`
|
82
|
+
params = mock(:params)
|
83
|
+
params.should_receive(:[]).with('html').any_number_of_times.and_return(mock(:html, :value => false))
|
84
|
+
params.should_receive(:[]).with('text').any_number_of_times.and_return(mock(:text, :value => false))
|
85
|
+
params.should_receive(:[]).with('textmate').any_number_of_times.and_return(mock(:textmate, :value => true))
|
86
|
+
params.should_receive(:[]).with('file_and_line').any_number_of_times.and_return(mock(:file_and_line, :value => false))
|
87
|
+
params.should_receive(:[]).with('dir').any_number_of_times.and_return(mock(:dir, :values => ['bin', 'config', 'lib', 'spec'], :values= => nil))
|
88
|
+
params.should_receive(:[]).with('rails').any_number_of_times.and_return(mock(:rails, :given? => nil, :value => nil))
|
89
|
+
params.should_receive(:[]).with('gems').any_number_of_times.and_return(mock(:gems, :given? => nil, :value => nil))
|
90
|
+
params.should_receive(:[]).with('only_rails').any_number_of_times.and_return(mock(:only_rails, :value => nil))
|
91
|
+
params.should_receive(:[]).with('only_gems').any_number_of_times.and_return(mock(:only_gems, :value => nil))
|
92
|
+
params.should_receive(:[]).with('regex').any_number_of_times.and_return(mock(:regex, :value => nil))
|
93
|
+
params.should_receive(:[]).with('case').any_number_of_times.and_return(mock(:case, :value => nil))
|
94
|
+
params.should_receive(:[]).with('count').any_number_of_times.and_return(mock(:count, :value => nil))
|
95
|
+
params.should_receive(:[]).with('verbose').any_number_of_times.and_return(mock(:verbose, :value => nil))
|
96
|
+
params.should_receive(:[]).with('wait').any_number_of_times.and_return(mock(:wait, :value => true))
|
97
|
+
params.should_receive(:[]).with('what_to_search_for').any_number_of_times.and_return(mock(:what_to_search_for, :values => ["Steven Soroka"]))
|
98
|
+
|
99
|
+
grepmate = Grepmate.new(params)
|
100
|
+
# hijack the output class so that it doesn't send the system() call.
|
101
|
+
output_class = Output::Textmate.new(grepmate)
|
102
|
+
output_class.should_receive(:system).any_number_of_times # .with("mate -w blah blah"). I'm not going to try to guess all the finds.
|
103
|
+
output_class.stub!(:print) # I don't want to see the output.
|
104
|
+
output_class.stub!(:puts) # I don't want to see the output.
|
105
|
+
|
106
|
+
Output::Textmate.stub!(:new).and_return(output_class)
|
107
|
+
|
108
|
+
grepmate.find
|
109
|
+
grepmate.display
|
110
|
+
end
|
111
|
+
|
112
|
+
it "should output file and line number commands" do
|
113
|
+
`bin/grepmate -f "module Output"`.split("\n").first.should =~ %r(lib/output/file_and_line\.rb:1)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
data/spec/spec_helper.rb
ADDED
data/tmp/grepmate.html
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
<html><head> <style type="text/css">body { background-color: #EEEEEE; } pre {
|
2
|
+
display: inline; } .ruby { font-family: Monaco; font-size: 10pt;
|
3
|
+
background-color: white } .ruby .normal {} .ruby .comment { color:
|
4
|
+
#005; font-style: italic; } .ruby .keyword { color: #A00; font-weight:
|
5
|
+
bold; } .ruby .method { color: #077; } .ruby .class { color: #074; }
|
6
|
+
.ruby .module { color: #050; } .ruby .punct { color: #447; font-weight:
|
7
|
+
bold; } .ruby .symbol { color: #099; } .ruby .string { color: #944;
|
8
|
+
background: #FFE; } .ruby .char { color: #F07; } .ruby .ident { color:
|
9
|
+
#004; } .ruby .constant { color: #07F; } .ruby .regex { color: #B66;
|
10
|
+
background: #FEF; } .ruby .number { color: #F99; } .ruby .attribute {
|
11
|
+
color: #7BB; } .ruby .global { color: #7FB; } .ruby .expr { color:
|
12
|
+
#227; } .ruby .escape { color: #277; } .ruby .highlight {
|
13
|
+
background-color: yellow; font-weight: 900; } td.lineno { text-align:
|
14
|
+
right; font-family: Monaco; font-size: 9pt; padding-right: 10px; }
|
15
|
+
td.filename { padding-top: 35px; font-family: Monaco; font-size: 14pt;
|
16
|
+
}</style>
|
17
|
+
|
18
|
+
<script type="text/javascript">
|
19
|
+
// http://www.nsftools.com/misc/SearchAndHighlight.htm
|
20
|
+
|
21
|
+
function doHighlight(bodyText,searchTerm,highlightStartTag,highlightEndTag)
|
22
|
+
{if((!highlightStartTag)||(!highlightEndTag)){highlightStartTag="<font style='color:blue; background-color:yellow;'>";highlightEndTag="</font>";}
|
23
|
+
var newText="";var i=-1;var lcSearchTerm=searchTerm.toLowerCase();var lcBodyText=bodyText.toLowerCase();while(bodyText.length>0){i=lcBodyText.indexOf(lcSearchTerm,i+1);if(i<0){newText+=bodyText;bodyText="";}else{if(bodyText.lastIndexOf(">",i)>=bodyText.lastIndexOf("<",i)){if(lcBodyText.lastIndexOf("/script>",i)>=lcBodyText.lastIndexOf("<script",i)){newText+=bodyText.substring(0,i)+highlightStartTag+bodyText.substr(i,searchTerm.length)+highlightEndTag;bodyText=bodyText.substr(i+searchTerm.length);lcBodyText=bodyText.toLowerCase();i=-1;}}}}
|
24
|
+
return newText;}
|
25
|
+
function highlightSearchTerms(searchText,treatAsPhrase,warnOnFailure,highlightStartTag,highlightEndTag)
|
26
|
+
{if(treatAsPhrase){searchArray=[searchText];}else{searchArray=searchText.split(" ");}
|
27
|
+
if(!document.body||typeof(document.body.innerHTML)=="undefined"){if(warnOnFailure){alert("Sorry, for some reason the text of this page is unavailable. Searching will not work.");}
|
28
|
+
return false;}
|
29
|
+
var bodyText=document.body.innerHTML;for(var i=0;i<searchArray.length;i++){bodyText=doHighlight(bodyText,searchArray[i],highlightStartTag,highlightEndTag);}
|
30
|
+
document.body.innerHTML=bodyText;return true;}</script></script>
|
31
|
+
</head><body onLoad="highlightSearchTerms('Steven Soroka', false)"><table cellspacing="0" cellpadding="2"><tr><td colspan="2" class="filename"><a href="file://spec">spec</a>/<a href="txmt://open?url=file://spec/grepmate_spec.rb">grepmate_spec.rb</a></td></tr>
|
32
|
+
<tr><td class="lineno"><a href="txmt://open?url=file://spec/grepmate_spec.rb&line=19">19</a></td><td class="ruby"><pre> <span class="keyword">end</span></pre></td></tr>
|
33
|
+
<tr><td class="lineno"><a href="txmt://open?url=file://spec/grepmate_spec.rb&line=20">20</a></td><td class="ruby"><pre> </pre></td></tr>
|
34
|
+
<tr><td class="lineno"><a href="txmt://open?url=file://spec/grepmate_spec.rb&line=21">21</a></td><td class="ruby"><pre> <span class="ident">it</span> <span class="punct">"</span><span class="string">should behave when piped STDIN files</span><span class="punct">"</span> <span class="keyword">do</span></pre></td></tr>
|
35
|
+
<tr><td class="lineno"><a href="txmt://open?url=file://spec/grepmate_spec.rb&line=22">22</a></td><td class="ruby"><pre> `<span class="ident">echo</span> <span class="constant">LICENSE</span> <span class="punct">|</span> <span class="ident">bin</span><span class="punct">/</span><span class="ident">grepmate</span> <span class="punct">-</span><span class="ident">c</span> <span class="punct">"</span><span class="string">Steven Soroka</span><span class="punct">"`.</span><span class="ident">chomp</span><span class="punct">.</span><span class="ident">should</span> <span class="punct">==</span> <span class="punct">'</span><span class="string">Matches: 1</span><span class="punct">'</span></pre></td></tr>
|
36
|
+
<tr><td class="lineno"><a href="txmt://open?url=file://spec/grepmate_spec.rb&line=23">23</a></td><td class="ruby"><pre> <span class="keyword">end</span></pre></td></tr>
|
37
|
+
<tr><td class="lineno"><a href="txmt://open?url=file://spec/grepmate_spec.rb&line=24">24</a></td><td class="ruby"><pre> <span class="comment">#</span></pre></td></tr>
|
38
|
+
<tr><td class="lineno"><a href="txmt://open?url=file://spec/grepmate_spec.rb&line=25">25</a></td><td class="ruby"><pre> <span class="comment"># it "should search gems" do</span></pre></td></tr>
|
39
|
+
<tr><td class="lineno">...</td><td></td></tr><tr><td class="lineno"><a href="txmt://open?url=file://spec/grepmate_spec.rb&line=33">33</a></td><td class="ruby"><pre> <span class="comment"># end</span></pre></td></tr>
|
40
|
+
<tr><td class="lineno"><a href="txmt://open?url=file://spec/grepmate_spec.rb&line=34">34</a></td><td class="ruby"><pre> </pre></td></tr>
|
41
|
+
<tr><td class="lineno"><a href="txmt://open?url=file://spec/grepmate_spec.rb&line=35">35</a></td><td class="ruby"><pre> <span class="ident">it</span> <span class="punct">"</span><span class="string">should support regular expressions</span><span class="punct">"</span> <span class="keyword">do</span></pre></td></tr>
|
42
|
+
<tr><td class="lineno"><a href="txmt://open?url=file://spec/grepmate_spec.rb&line=36">36</a></td><td class="ruby"><pre> <span class="comment"># from LICENSE: this will match: Steven Soroka</span></pre></td></tr>
|
43
|
+
<tr><td class="lineno"><a href="txmt://open?url=file://spec/grepmate_spec.rb&line=37">37</a></td><td class="ruby"><pre> `<span class="ident">echo</span> <span class="constant">LICENSE</span> <span class="punct">|</span> <span class="ident">bin</span><span class="punct">/</span><span class="ident">grepmate</span> <span class="punct">-</span><span class="ident">c</span> <span class="punct">-</span><span class="ident">e</span> <span class="punct">"</span><span class="string">even .oro.a</span><span class="punct">"`.</span><span class="ident">chomp</span><span class="punct">.</span><span class="ident">should</span> <span class="punct">==</span> <span class="punct">'</span><span class="string">Matches: 1</span><span class="punct">'</span></pre></td></tr>
|
44
|
+
<tr><td class="lineno"><a href="txmt://open?url=file://spec/grepmate_spec.rb&line=38">38</a></td><td class="ruby"><pre> <span class="keyword">end</span></pre></td></tr>
|
45
|
+
<tr><td class="lineno"><a href="txmt://open?url=file://spec/grepmate_spec.rb&line=39">39</a></td><td class="ruby"><pre> </pre></td></tr>
|
46
|
+
<tr><td class="lineno"><a href="txmt://open?url=file://spec/grepmate_spec.rb&line=40">40</a></td><td class="ruby"><pre> <span class="ident">describe</span> <span class="punct">'</span><span class="string">output</span><span class="punct">'</span> <span class="keyword">do</span></pre></td></tr>
|
47
|
+
<tr><td class="lineno"><a href="txmt://open?url=file://spec/grepmate_spec.rb&line=41">41</a></td><td class="ruby"><pre> <span class="ident">it</span> <span class="punct">"</span><span class="string">should output text</span><span class="punct">"</span> <span class="keyword">do</span></pre></td></tr>
|
48
|
+
<tr><td class="lineno"><a href="txmt://open?url=file://spec/grepmate_spec.rb&line=42">42</a></td><td class="ruby"><pre> <span class="ident">result</span> <span class="punct">=</span> `<span class="ident">bin</span><span class="punct">/</span><span class="ident">grepmate</span> <span class="punct">--</span><span class="ident">text</span> <span class="punct">'</span><span class="string">Steven Soroka</span><span class="punct">'`</span></pre></td></tr>
|
49
|
+
<tr><td class="lineno"><a href="txmt://open?url=file://spec/grepmate_spec.rb&line=43">43</a></td><td class="ruby"><pre> <span class="comment"># spec/grepmate_spec.rb:22: `echo LICENSE | bin/grepmate -c "Steven Soroka"`.chomp.should == 'Matches: 1'</span></pre></td></tr>
|
50
|
+
<tr><td class="lineno"><a href="txmt://open?url=file://spec/grepmate_spec.rb&line=44">44</a></td><td class="ruby"><pre> <span class="comment"># spec/grepmate_spec.rb:36: # from LICENSE: this will match: Steven Soroka</span></pre></td></tr>
|
51
|
+
<tr><td class="lineno"><a href="txmt://open?url=file://spec/grepmate_spec.rb&line=45">45</a></td><td class="ruby"><pre> <span class="comment"># spec/grepmate_spec.rb:42: puts `bin/grepmate --text 'Steven Soroka'`</span></pre></td></tr>
|
52
|
+
<tr><td class="lineno"><a href="txmt://open?url=file://spec/grepmate_spec.rb&line=46">46</a></td><td class="ruby"><pre> <span class="comment"># spec/grepmate_spec.rb:46: # `bin/grepmate --html 'Steven Soroka'`</span></pre></td></tr>
|
53
|
+
<tr><td class="lineno"><a href="txmt://open?url=file://spec/grepmate_spec.rb&line=47">47</a></td><td class="ruby"><pre> <span class="comment"># spec/grepmate_spec.rb:61: params.(blah blah blah blah blah blah blah blah blah blah)s => ["Steven Soroka"]))</span></pre></td></tr>
|
54
|
+
<tr><td class="lineno"><a href="txmt://open?url=file://spec/grepmate_spec.rb&line=48">48</a></td><td class="ruby"><pre> <span class="ident">result</span><span class="punct">.</span><span class="ident">should</span> <span class="punct">=~</span> <span class="punct">/</span><span class="regex">grepmate_spec</span><span class="punct">/</span></pre></td></tr>
|
55
|
+
<tr><td class="lineno"><a href="txmt://open?url=file://spec/grepmate_spec.rb&line=49">49</a></td><td class="ruby"><pre> <span class="keyword">end</span></pre></td></tr>
|
56
|
+
<tr><td class="lineno"><a href="txmt://open?url=file://spec/grepmate_spec.rb&line=50">50</a></td><td class="ruby"><pre> </pre></td></tr>
|
57
|
+
<tr><td class="lineno"><a href="txmt://open?url=file://spec/grepmate_spec.rb&line=51">51</a></td><td class="ruby"><pre> <span class="ident">it</span> <span class="punct">"</span><span class="string">should output html</span><span class="punct">"</span> <span class="keyword">do</span></pre></td></tr>
|
58
|
+
<tr><td class="lineno"><a href="txmt://open?url=file://spec/grepmate_spec.rb&line=52">52</a></td><td class="ruby"><pre> <span class="comment"># `bin/grepmate --html 'Steven Soroka'`</span></pre></td></tr>
|
59
|
+
<tr><td class="lineno"><a href="txmt://open?url=file://spec/grepmate_spec.rb&line=53">53</a></td><td class="ruby"><pre> <span class="ident">params</span> <span class="punct">=</span> <span class="ident">mock</span><span class="punct">(</span><span class="symbol">:params</span><span class="punct">)</span></pre></td></tr>
|
60
|
+
<tr><td class="lineno"><a href="txmt://open?url=file://spec/grepmate_spec.rb&line=54">54</a></td><td class="ruby"><pre> <span class="ident">params</span><span class="punct">.</span><span class="ident">should_receive</span><span class="punct">(:[]).</span><span class="ident">with</span><span class="punct">('</span><span class="string">html</span><span class="punct">').</span><span class="ident">any_number_of_times</span><span class="punct">.</span><span class="ident">and_return</span><span class="punct">(</span><span class="ident">mock</span><span class="punct">(</span><span class="symbol">:html</span><span class="punct">,</span> <span class="symbol">:value</span> <span class="punct">=></span> <span class="constant">true</span><span class="punct">))</span></pre></td></tr>
|
61
|
+
<tr><td class="lineno"><a href="txmt://open?url=file://spec/grepmate_spec.rb&line=55">55</a></td><td class="ruby"><pre> <span class="ident">params</span><span class="punct">.</span><span class="ident">should_receive</span><span class="punct">(:[]).</span><span class="ident">with</span><span class="punct">('</span><span class="string">text</span><span class="punct">').</span><span class="ident">any_number_of_times</span><span class="punct">.</span><span class="ident">and_return</span><span class="punct">(</span><span class="ident">mock</span><span class="punct">(</span><span class="symbol">:text</span><span class="punct">,</span> <span class="symbol">:value</span> <span class="punct">=></span> <span class="constant">false</span><span class="punct">))</span></pre></td></tr>
|
62
|
+
<tr><td class="lineno">...</td><td></td></tr><tr><td class="lineno"><a href="txmt://open?url=file://spec/grepmate_spec.rb&line=64">64</a></td><td class="ruby"><pre> <span class="ident">params</span><span class="punct">.</span><span class="ident">should_receive</span><span class="punct">(:[]).</span><span class="ident">with</span><span class="punct">('</span><span class="string">case</span><span class="punct">').</span><span class="ident">any_number_of_times</span><span class="punct">.</span><span class="ident">and_return</span><span class="punct">(</span><span class="ident">mock</span><span class="punct">(</span><span class="symbol">:case</span><span class="punct">,</span> <span class="symbol">:value</span> <span class="punct">=></span> <span class="constant">nil</span><span class="punct">))</span></pre></td></tr>
|
63
|
+
<tr><td class="lineno"><a href="txmt://open?url=file://spec/grepmate_spec.rb&line=65">65</a></td><td class="ruby"><pre> <span class="ident">params</span><span class="punct">.</span><span class="ident">should_receive</span><span class="punct">(:[]).</span><span class="ident">with</span><span class="punct">('</span><span class="string">count</span><span class="punct">').</span><span class="ident">any_number_of_times</span><span class="punct">.</span><span class="ident">and_return</span><span class="punct">(</span><span class="ident">mock</span><span class="punct">(</span><span class="symbol">:count</span><span class="punct">,</span> <span class="symbol">:value</span> <span class="punct">=></span> <span class="constant">nil</span><span class="punct">))</span></pre></td></tr>
|
64
|
+
<tr><td class="lineno"><a href="txmt://open?url=file://spec/grepmate_spec.rb&line=66">66</a></td><td class="ruby"><pre> <span class="ident">params</span><span class="punct">.</span><span class="ident">should_receive</span><span class="punct">(:[]).</span><span class="ident">with</span><span class="punct">('</span><span class="string">verbose</span><span class="punct">').</span><span class="ident">any_number_of_times</span><span class="punct">.</span><span class="ident">and_return</span><span class="punct">(</span><span class="ident">mock</span><span class="punct">(</span><span class="symbol">:verbose</span><span class="punct">,</span> <span class="symbol">:value</span> <span class="punct">=></span> <span class="constant">nil</span><span class="punct">))</span></pre></td></tr>
|
65
|
+
<tr><td class="lineno"><a href="txmt://open?url=file://spec/grepmate_spec.rb&line=67">67</a></td><td class="ruby"><pre> <span class="ident">params</span><span class="punct">.</span><span class="ident">should_receive</span><span class="punct">(:[]).</span><span class="ident">with</span><span class="punct">('</span><span class="string">what_to_search_for</span><span class="punct">').</span><span class="ident">any_number_of_times</span><span class="punct">.</span><span class="ident">and_return</span><span class="punct">(</span><span class="ident">mock</span><span class="punct">(</span><span class="symbol">:what_to_search_for</span><span class="punct">,</span> <span class="symbol">:values</span> <span class="punct">=></span> <span class="punct">["</span><span class="string">Steven Soroka</span><span class="punct">"]))</span></pre></td></tr>
|
66
|
+
<tr><td class="lineno"><a href="txmt://open?url=file://spec/grepmate_spec.rb&line=68">68</a></td><td class="ruby"><pre> </pre></td></tr>
|
67
|
+
<tr><td class="lineno"><a href="txmt://open?url=file://spec/grepmate_spec.rb&line=69">69</a></td><td class="ruby"><pre> <span class="ident">grepmate</span> <span class="punct">=</span> <span class="constant">Grepmate</span><span class="punct">.</span><span class="ident">new</span><span class="punct">(</span><span class="ident">params</span><span class="punct">)</span></pre></td></tr>
|
68
|
+
<tr><td class="lineno"><a href="txmt://open?url=file://spec/grepmate_spec.rb&line=70">70</a></td><td class="ruby"><pre> <span class="comment"># hijack the output class so that it doesn't send the system() call.</span></pre></td></tr>
|
69
|
+
<tr><td class="lineno">...</td><td></td></tr><tr><td class="lineno"><a href="txmt://open?url=file://spec/grepmate_spec.rb&line=78">78</a></td><td class="ruby"><pre> <span class="keyword">end</span></pre></td></tr>
|
70
|
+
<tr><td class="lineno"><a href="txmt://open?url=file://spec/grepmate_spec.rb&line=79">79</a></td><td class="ruby"><pre> </pre></td></tr>
|
71
|
+
<tr><td class="lineno"><a href="txmt://open?url=file://spec/grepmate_spec.rb&line=80">80</a></td><td class="ruby"><pre> <span class="ident">it</span> <span class="punct">"</span><span class="string">should output textmate commands</span><span class="punct">"</span> <span class="keyword">do</span></pre></td></tr>
|
72
|
+
<tr><td class="lineno"><a href="txmt://open?url=file://spec/grepmate_spec.rb&line=81">81</a></td><td class="ruby"><pre> <span class="comment"># `bin/grepmate --textmate 'Steven Soroka'`</span></pre></td></tr>
|
73
|
+
<tr><td class="lineno"><a href="txmt://open?url=file://spec/grepmate_spec.rb&line=82">82</a></td><td class="ruby"><pre> <span class="ident">params</span> <span class="punct">=</span> <span class="ident">mock</span><span class="punct">(</span><span class="symbol">:params</span><span class="punct">)</span></pre></td></tr>
|
74
|
+
<tr><td class="lineno"><a href="txmt://open?url=file://spec/grepmate_spec.rb&line=83">83</a></td><td class="ruby"><pre> <span class="ident">params</span><span class="punct">.</span><span class="ident">should_receive</span><span class="punct">(:[]).</span><span class="ident">with</span><span class="punct">('</span><span class="string">html</span><span class="punct">').</span><span class="ident">any_number_of_times</span><span class="punct">.</span><span class="ident">and_return</span><span class="punct">(</span><span class="ident">mock</span><span class="punct">(</span><span class="symbol">:html</span><span class="punct">,</span> <span class="symbol">:value</span> <span class="punct">=></span> <span class="constant">false</span><span class="punct">))</span></pre></td></tr>
|
75
|
+
<tr><td class="lineno"><a href="txmt://open?url=file://spec/grepmate_spec.rb&line=84">84</a></td><td class="ruby"><pre> <span class="ident">params</span><span class="punct">.</span><span class="ident">should_receive</span><span class="punct">(:[]).</span><span class="ident">with</span><span class="punct">('</span><span class="string">text</span><span class="punct">').</span><span class="ident">any_number_of_times</span><span class="punct">.</span><span class="ident">and_return</span><span class="punct">(</span><span class="ident">mock</span><span class="punct">(</span><span class="symbol">:text</span><span class="punct">,</span> <span class="symbol">:value</span> <span class="punct">=></span> <span class="constant">false</span><span class="punct">))</span></pre></td></tr>
|
76
|
+
<tr><td class="lineno">...</td><td></td></tr><tr><td class="lineno"><a href="txmt://open?url=file://spec/grepmate_spec.rb&line=94">94</a></td><td class="ruby"><pre> <span class="ident">params</span><span class="punct">.</span><span class="ident">should_receive</span><span class="punct">(:[]).</span><span class="ident">with</span><span class="punct">('</span><span class="string">count</span><span class="punct">').</span><span class="ident">any_number_of_times</span><span class="punct">.</span><span class="ident">and_return</span><span class="punct">(</span><span class="ident">mock</span><span class="punct">(</span><span class="symbol">:count</span><span class="punct">,</span> <span class="symbol">:value</span> <span class="punct">=></span> <span class="constant">nil</span><span class="punct">))</span></pre></td></tr>
|
77
|
+
<tr><td class="lineno"><a href="txmt://open?url=file://spec/grepmate_spec.rb&line=95">95</a></td><td class="ruby"><pre> <span class="ident">params</span><span class="punct">.</span><span class="ident">should_receive</span><span class="punct">(:[]).</span><span class="ident">with</span><span class="punct">('</span><span class="string">verbose</span><span class="punct">').</span><span class="ident">any_number_of_times</span><span class="punct">.</span><span class="ident">and_return</span><span class="punct">(</span><span class="ident">mock</span><span class="punct">(</span><span class="symbol">:verbose</span><span class="punct">,</span> <span class="symbol">:value</span> <span class="punct">=></span> <span class="constant">nil</span><span class="punct">))</span></pre></td></tr>
|
78
|
+
<tr><td class="lineno"><a href="txmt://open?url=file://spec/grepmate_spec.rb&line=96">96</a></td><td class="ruby"><pre> <span class="ident">params</span><span class="punct">.</span><span class="ident">should_receive</span><span class="punct">(:[]).</span><span class="ident">with</span><span class="punct">('</span><span class="string">wait</span><span class="punct">').</span><span class="ident">any_number_of_times</span><span class="punct">.</span><span class="ident">and_return</span><span class="punct">(</span><span class="ident">mock</span><span class="punct">(</span><span class="symbol">:wait</span><span class="punct">,</span> <span class="symbol">:value</span> <span class="punct">=></span> <span class="constant">true</span><span class="punct">))</span></pre></td></tr>
|
79
|
+
<tr><td class="lineno"><a href="txmt://open?url=file://spec/grepmate_spec.rb&line=97">97</a></td><td class="ruby"><pre> <span class="ident">params</span><span class="punct">.</span><span class="ident">should_receive</span><span class="punct">(:[]).</span><span class="ident">with</span><span class="punct">('</span><span class="string">what_to_search_for</span><span class="punct">').</span><span class="ident">any_number_of_times</span><span class="punct">.</span><span class="ident">and_return</span><span class="punct">(</span><span class="ident">mock</span><span class="punct">(</span><span class="symbol">:what_to_search_for</span><span class="punct">,</span> <span class="symbol">:values</span> <span class="punct">=></span> <span class="punct">["</span><span class="string">Steven Soroka</span><span class="punct">"]))</span></pre></td></tr>
|
80
|
+
<tr><td class="lineno"><a href="txmt://open?url=file://spec/grepmate_spec.rb&line=98">98</a></td><td class="ruby"><pre> </pre></td></tr>
|
81
|
+
<tr><td class="lineno"><a href="txmt://open?url=file://spec/grepmate_spec.rb&line=99">99</a></td><td class="ruby"><pre> <span class="ident">grepmate</span> <span class="punct">=</span> <span class="constant">Grepmate</span><span class="punct">.</span><span class="ident">new</span><span class="punct">(</span><span class="ident">params</span><span class="punct">)</span></pre></td></tr>
|
82
|
+
<tr><td class="lineno"><a href="txmt://open?url=file://spec/grepmate_spec.rb&line=100">100</a></td><td class="ruby"><pre> <span class="comment"># hijack the output class so that it doesn't send the system() call.</span></pre></td></tr>
|
83
|
+
</table></body></html>
|
metadata
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: grepmate
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.0.5
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Steven Soroka
|
8
|
+
- Zach Holt
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2009-10-16 00:00:00 -05:00
|
14
|
+
default_executable: grepmate
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: main
|
18
|
+
type: :runtime
|
19
|
+
version_requirement:
|
20
|
+
version_requirements: !ruby/object:Gem::Requirement
|
21
|
+
requirements:
|
22
|
+
- - ">="
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: 2.8.3
|
25
|
+
version:
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: syntax
|
28
|
+
type: :runtime
|
29
|
+
version_requirement:
|
30
|
+
version_requirements: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: 1.0.0
|
35
|
+
version:
|
36
|
+
description: Extremely fast search of rails projects or rails source for code, open in textmate or browser with html output
|
37
|
+
email: ssoroka78@gmail.com
|
38
|
+
executables:
|
39
|
+
- grepmate
|
40
|
+
extensions: []
|
41
|
+
|
42
|
+
extra_rdoc_files:
|
43
|
+
- LICENSE
|
44
|
+
- README.rdoc
|
45
|
+
files:
|
46
|
+
- .gitignore
|
47
|
+
- LICENSE
|
48
|
+
- README.rdoc
|
49
|
+
- Rakefile
|
50
|
+
- VERSION
|
51
|
+
- bin/grepmate
|
52
|
+
- config/dot-grepmate
|
53
|
+
- grepmate.gemspec
|
54
|
+
- lib/.empty
|
55
|
+
- lib/.git-empty
|
56
|
+
- lib/grepmate.rb
|
57
|
+
- lib/output/file_and_line.rb
|
58
|
+
- lib/output/html.rb
|
59
|
+
- lib/output/text.rb
|
60
|
+
- lib/output/textmate.rb
|
61
|
+
- spec/grepmate_spec.rb
|
62
|
+
- spec/spec_helper.rb
|
63
|
+
- tmp/grepmate.html
|
64
|
+
has_rdoc: true
|
65
|
+
homepage: http://github.com/ssoroka/grepmate
|
66
|
+
licenses: []
|
67
|
+
|
68
|
+
post_install_message:
|
69
|
+
rdoc_options:
|
70
|
+
- --charset=UTF-8
|
71
|
+
require_paths:
|
72
|
+
- lib
|
73
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: "0"
|
78
|
+
version:
|
79
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: "0"
|
84
|
+
version:
|
85
|
+
requirements: []
|
86
|
+
|
87
|
+
rubyforge_project:
|
88
|
+
rubygems_version: 1.3.5
|
89
|
+
signing_key:
|
90
|
+
specification_version: 3
|
91
|
+
summary: Extremely fast search of rails projects or rails source for code, open in textmate or browser with html output
|
92
|
+
test_files:
|
93
|
+
- spec/grepmate_spec.rb
|
94
|
+
- spec/spec_helper.rb
|