grep-fu 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +166 -0
- data/VERSION +1 -1
- data/bin/grep-fu +1 -1
- data/grep-fu.gemspec +4 -4
- metadata +5 -5
- data/README.rdoc +0 -106
data/README.md
ADDED
@@ -0,0 +1,166 @@
|
|
1
|
+
Grep-Fu
|
2
|
+
=======
|
3
|
+
|
4
|
+
Grep-Fu is a very fast, Rails-oriented command-line helper script for grep. It's a ruby wrapper for speeding up text searches within the files of a Rails project. The simplest, common usage:
|
5
|
+
|
6
|
+
grep-fu account_deletion
|
7
|
+
|
8
|
+
This will display a list of files which contain the search text:
|
9
|
+
|
10
|
+
./app/models/account.rb
|
11
|
+
./app/controllers/accounts_controller.rb
|
12
|
+
|
13
|
+
*NOTE:* Grep-Fu will only work as expected if you are in the root directory of a Rails project!
|
14
|
+
|
15
|
+
Installation
|
16
|
+
------------
|
17
|
+
|
18
|
+
Grep-Fu is now a gem:
|
19
|
+
|
20
|
+
gem install grep-fu
|
21
|
+
|
22
|
+
Often, it can help reduce typing by aliasing the admittedly lengthy "grep-fu" command:
|
23
|
+
|
24
|
+
alias g='grep-fu'
|
25
|
+
|
26
|
+
Putting this (or a similar shortcut) in your .bashrc or .profile will allow you to use a shorthand version of the command:
|
27
|
+
|
28
|
+
g account_deletion
|
29
|
+
|
30
|
+
Even Faster
|
31
|
+
-----------
|
32
|
+
|
33
|
+
For more targeted (faster) searches, you can specify one of the following flags to narrow down the search:
|
34
|
+
|
35
|
+
a - app
|
36
|
+
m - app/models
|
37
|
+
c - app/controllers
|
38
|
+
v - app/views
|
39
|
+
h - app/helpers
|
40
|
+
|
41
|
+
l - lib
|
42
|
+
|
43
|
+
p - public
|
44
|
+
css - public/stylesheets
|
45
|
+
js - public/javascripts
|
46
|
+
|
47
|
+
s - spec
|
48
|
+
t - test
|
49
|
+
|
50
|
+
vp - vendor/plugins
|
51
|
+
mig - db/migrate
|
52
|
+
|
53
|
+
So to search only your helpers for the term "helpless":
|
54
|
+
|
55
|
+
grep-fu h helpless
|
56
|
+
|
57
|
+
Multiple word searches and searches containing special regex characters should be surrounded by quotes:
|
58
|
+
|
59
|
+
grep-fu s "should be tested"
|
60
|
+
|
61
|
+
grep-fu "^[^\?] fishy fishy fishy fish$"
|
62
|
+
|
63
|
+
Running grep-fu without parameters will show you what options are available.
|
64
|
+
|
65
|
+
Off the Beaten Path
|
66
|
+
----------------------------
|
67
|
+
|
68
|
+
Occasionally, you'll want to search a directory that's not defined in one of the targeted paths, but you don't want to scan the entire Rails project. In that case, you can provide a specific directory to grep:
|
69
|
+
|
70
|
+
grep-fu lib/tasks troweler
|
71
|
+
|
72
|
+
You can even step up out of the current directory. Grep-Fu will use any path shortcuts your underlying OS recognizes.
|
73
|
+
|
74
|
+
grep-fu ../../different_rails_project "def similar_method"
|
75
|
+
|
76
|
+
grep-fu ~/Projects/roger_tracking last_known_location
|
77
|
+
|
78
|
+
I want to see what it found!
|
79
|
+
----------------------------
|
80
|
+
|
81
|
+
For more detail, you can add the '--verbose' flag to command:
|
82
|
+
|
83
|
+
grep-fu c budget_dragon --verbose
|
84
|
+
|
85
|
+
This will output the filename, line number, and found line.
|
86
|
+
|
87
|
+
./app/model/budget.rb:18:
|
88
|
+
budget_dragon # Bob in accounting's been drinking again
|
89
|
+
|
90
|
+
This should be used for fairly narrow searches, as it can produce a whole lot of output.
|
91
|
+
|
92
|
+
Thanks go out to [Scotty Moon](http://github.com/scottymoon) for this feature.
|
93
|
+
|
94
|
+
Colors
|
95
|
+
------
|
96
|
+
|
97
|
+
If you'd like to see grep-fu's output in color, add the '--color' flag:
|
98
|
+
|
99
|
+
grep-fu mig ExtraBiggened --color --verbose
|
100
|
+
|
101
|
+
Under most color schemes, the --color option is only useful if --verbose is used as well.
|
102
|
+
|
103
|
+
If you'd rather have color all the time, you can change the setting COLOR_ON_BY_DEFAULT in the code to true. If you do this, then you can use the '--no-color' flag to disable the feature:
|
104
|
+
|
105
|
+
grep-fu mig DoublePlusUnBiggened --no-color
|
106
|
+
|
107
|
+
Thanks go out to [Joshua French](http://github.com/osake) for this feature.
|
108
|
+
|
109
|
+
Single-Line Output
|
110
|
+
------------------
|
111
|
+
|
112
|
+
Sometimes you need to output all the files grep-fu finds onto a single line; for example, when piping the list into another command:
|
113
|
+
|
114
|
+
grep-fu "# Pipe me!" --single-line
|
115
|
+
|
116
|
+
The list of files with matches will display on a single line:
|
117
|
+
|
118
|
+
./test/unit/calamity_test.rb ./test/unit/havoc_test.rb ./test/unit/mayhem_test.rb...
|
119
|
+
|
120
|
+
Ignoring More Stuff
|
121
|
+
---------------------
|
122
|
+
|
123
|
+
When performing an untargeted search, Grep-fu determines which directories to skip by using the PRUNE_PATHS constant. If you have a directory you'd like to skip searching by default, simply add its path (relative to the Rails root) to PRUNE_PATHS.
|
124
|
+
|
125
|
+
For example, if you have an unusually large set of migrations, you might want to step over them by default. Change the line
|
126
|
+
|
127
|
+
PRUNE_PATHS = ['/.svn', '/.git', '/vendor', '/log', '/public', '/tmp', '/coverage']
|
128
|
+
|
129
|
+
to
|
130
|
+
|
131
|
+
PRUNE_PATHS = ['/.svn', '/.git', '/vendor', '/log', '/public', '/tmp', '/coverage', '/db/migrations']
|
132
|
+
|
133
|
+
And migrations will no longer be searched. Note that targeted searches and specified directories always override the PRUNE_PATHS option.
|
134
|
+
|
135
|
+
Technical mumbo-jumbo
|
136
|
+
---------------------
|
137
|
+
|
138
|
+
Grep-Fu speeds up the searching process by only searching the files you care about. It does this by constructing a "find" command which is piped into grep. Find "prunes" the following search directories:
|
139
|
+
|
140
|
+
* public
|
141
|
+
* logs
|
142
|
+
* vendor
|
143
|
+
* tmp
|
144
|
+
* coverage
|
145
|
+
* .svn
|
146
|
+
* .git
|
147
|
+
|
148
|
+
Note that all these directories are still searchable with targeted searches or a directory specification; they're simply not searched by default
|
149
|
+
|
150
|
+
Grep-fu also ignores files larger than 100K, which tend to be unsearchable binaries.
|
151
|
+
|
152
|
+
The pruning options for find are some of the ugliest in the CLI world. Using Ruby allows us to construct a giant, hideous command that does exactly what we need.
|
153
|
+
|
154
|
+
Note on Patches/Pull Requests
|
155
|
+
-----------------------------
|
156
|
+
|
157
|
+
* Fork the project.
|
158
|
+
* Make your feature addition or bug fix.
|
159
|
+
* Commit, do not mess with rakefile, version, or history.
|
160
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
161
|
+
* Send me a pull request. Bonus points for topic branches.
|
162
|
+
|
163
|
+
Copyright
|
164
|
+
---------
|
165
|
+
|
166
|
+
Copyright (c) 2010 Eric Budd. See LICENSE for details.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.4.0
|
data/bin/grep-fu
CHANGED
@@ -16,7 +16,7 @@ PATH_REPLACEMENTS = {
|
|
16
16
|
'mig' => 'db/migrate'
|
17
17
|
}
|
18
18
|
|
19
|
-
PRUNE_PATHS = ['/.svn', '/.git', '/vendor', '/log', '/public
|
19
|
+
PRUNE_PATHS = ['/.svn', '/.git', '/vendor', '/log', '/public', '/tmp', '/coverage']
|
20
20
|
COLOR_ON_BY_DEFAULT = false
|
21
21
|
options = '-ril'
|
22
22
|
|
data/grep-fu.gemspec
CHANGED
@@ -5,22 +5,22 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{grep-fu}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.4.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Eric Budd"]
|
12
|
-
s.date = %q{2010-05-
|
12
|
+
s.date = %q{2010-05-27}
|
13
13
|
s.default_executable = %q{grep-fu}
|
14
14
|
s.description = %q{Grep-Fu is a very fast, Rails-oriented command-line helper script for grep.}
|
15
15
|
s.email = %q{calamitous@calamitylane.com}
|
16
16
|
s.executables = ["grep-fu"]
|
17
17
|
s.extra_rdoc_files = [
|
18
18
|
"LICENSE",
|
19
|
-
"README.
|
19
|
+
"README.md"
|
20
20
|
]
|
21
21
|
s.files = [
|
22
22
|
"LICENSE",
|
23
|
-
"README.
|
23
|
+
"README.md",
|
24
24
|
"Rakefile",
|
25
25
|
"VERSION",
|
26
26
|
"bin/grep-fu",
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
7
|
+
- 4
|
8
8
|
- 0
|
9
|
-
version: 0.
|
9
|
+
version: 0.4.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Eric Budd
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-05-
|
17
|
+
date: 2010-05-27 00:00:00 -05:00
|
18
18
|
default_executable: grep-fu
|
19
19
|
dependencies: []
|
20
20
|
|
@@ -26,10 +26,10 @@ extensions: []
|
|
26
26
|
|
27
27
|
extra_rdoc_files:
|
28
28
|
- LICENSE
|
29
|
-
- README.
|
29
|
+
- README.md
|
30
30
|
files:
|
31
31
|
- LICENSE
|
32
|
-
- README.
|
32
|
+
- README.md
|
33
33
|
- Rakefile
|
34
34
|
- VERSION
|
35
35
|
- bin/grep-fu
|
data/README.rdoc
DELETED
@@ -1,106 +0,0 @@
|
|
1
|
-
Grep-Fu
|
2
|
-
=======
|
3
|
-
|
4
|
-
Grep-Fu is a very fast, Rails-oriented command-line helper script for grep. It's a ruby wrapper for speeding up text searches within the files of a Rails project. The simplest, common usage:
|
5
|
-
|
6
|
-
grep-fu account_deletion
|
7
|
-
|
8
|
-
This will display a list of files which contain the search text:
|
9
|
-
|
10
|
-
./app/models/account.rb
|
11
|
-
./app/controllers/accounts_controller.rb
|
12
|
-
|
13
|
-
*NOTE:* Grep-Fu will only work as expected if you are in the root directory of a Rails project!
|
14
|
-
|
15
|
-
It's a standalone script, so you can just drop it in any PATHed directory, chmod 777 it (or 700, for the paranoid) and go to town.
|
16
|
-
|
17
|
-
Even Faster
|
18
|
-
-----------
|
19
|
-
|
20
|
-
For more targeted (faster) searches, you can specify one of the following flags to narrow down the search:
|
21
|
-
|
22
|
-
a - app
|
23
|
-
m - app/models
|
24
|
-
c - app/controllers
|
25
|
-
v - app/views
|
26
|
-
h - app/helpers
|
27
|
-
|
28
|
-
l - lib
|
29
|
-
|
30
|
-
p - public
|
31
|
-
css - public/stylesheets
|
32
|
-
js - public/javascripts
|
33
|
-
|
34
|
-
s - spec
|
35
|
-
t - test
|
36
|
-
|
37
|
-
vp - vendor/plugins
|
38
|
-
mig - db/migrate
|
39
|
-
|
40
|
-
So to search only your helpers for the term "helpless":
|
41
|
-
|
42
|
-
grep-fu h helpless
|
43
|
-
|
44
|
-
Multiple word searches and searches containing special regex characters should be surrounded by quotes:
|
45
|
-
|
46
|
-
grep-fu s "should be tested"
|
47
|
-
|
48
|
-
grep-fu "^[^\?] fishy fishy fishy fish$"
|
49
|
-
|
50
|
-
Running grep-fu without a search will show you what options are available.
|
51
|
-
|
52
|
-
I want to see what it found!
|
53
|
-
----------------------------
|
54
|
-
|
55
|
-
For more detail, you can add the '--verbose' flag to command:
|
56
|
-
|
57
|
-
grep-fu c budget_dragon --verbose
|
58
|
-
|
59
|
-
This will output the filename, line number, and found line. This should be used for fairly narrow searches, as it can produce a whole lot of output.
|
60
|
-
|
61
|
-
Thanks go out to [Scotty Moon](http://github.com/scottymoon) for this feature.
|
62
|
-
|
63
|
-
Colors
|
64
|
-
------
|
65
|
-
|
66
|
-
If you'd like to see grep-fu's output in color, add the '--color' flag to your output:
|
67
|
-
|
68
|
-
grep-fu mig ExtraBiggened --color --verbose
|
69
|
-
|
70
|
-
This will output your results in color (under most color schemes, this is only useful if --verbose is used as well). If you'd rather just leave color on all the time, you can change the setting COLOR_ON_BY_DEFAULT in the code to true. If you do this, then you can use the '--no-color' flag to disable the feature:
|
71
|
-
|
72
|
-
grep-fu mig DoublePlusUnBiggened --no-color
|
73
|
-
|
74
|
-
Thanks go out to [Joshua French](http://github.com/osake) for this feature.
|
75
|
-
|
76
|
-
Single-Line Output
|
77
|
-
------------------
|
78
|
-
|
79
|
-
Sometimes you may need to output all the files grep-fu outputs onto a single line; for example, when piping the list into another command:
|
80
|
-
|
81
|
-
grep-fu "# Pipe me!" --single-line
|
82
|
-
|
83
|
-
The list of files with matches will display on a single line:
|
84
|
-
|
85
|
-
./test/unit/calamity_test.rb ./test/unit/havoc_test.rb ./test/unit/mayhem_test.rb...
|
86
|
-
|
87
|
-
Technical mumbo-jumbo
|
88
|
-
---------------------
|
89
|
-
|
90
|
-
Grep-Fu speeds up the searching process by only searching the files you care about. It does this by constructing a find for grepping which "prunes" unwanted directories, such as logs and vendor plugins. Unfortunately, find's prune options are some of the ugliest in the CLI world. Using Ruby allows us to construct a giant ugly command that does exactly what we want.
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
== Note on Patches/Pull Requests
|
95
|
-
|
96
|
-
* Fork the project.
|
97
|
-
* Make your feature addition or bug fix.
|
98
|
-
* Add tests for it. This is important so I don't break it in a
|
99
|
-
future version unintentionally.
|
100
|
-
* Commit, do not mess with rakefile, version, or history.
|
101
|
-
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
102
|
-
* Send me a pull request. Bonus points for topic branches.
|
103
|
-
|
104
|
-
== Copyright
|
105
|
-
|
106
|
-
Copyright (c) 2010 Eric Budd. See LICENSE for details.
|