Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
d22efa6
Test file to ensure we're not mucking up the repo
osake Feb 1, 2010
4d2ea24
Fartin around
osake Feb 1, 2010
c9c126c
Merge branch 'master' of zkcdr1s4:grep-fu
osake Feb 1, 2010
9158331
Undoing what has been done\!
osake Feb 1, 2010
3b01144
Added option to have colors turned off by default if, say, your lapto…
Feb 8, 2009
f04663f
Removed embarrassing misspelling
Feb 23, 2009
930b212
Added 'coverage' to pruned directories
Feb 27, 2009
1c97308
Oops... deleted extraneous file
Mar 8, 2009
fb31906
Minor README tweaks
Oct 31, 2009
6d9bfad
Grep-fu can now output matches on a single line
Feb 27, 2010
d825dd4
Documentation includes a section on the single-line feature.
Mar 5, 2010
18777b8
Minor bugfix for disabling color
Mar 5, 2010
9ef2616
Oh yeah... it's *4* spaces for code blocks in Markdown...
Mar 5, 2010
525c8ee
Engemulating grep-fu!
May 12, 2010
3f09931
Converted RDoc file back into markdown
May 13, 2010
998abdd
Added installation instructions to README
May 27, 2010
bf3f3dd
Expansion and clarification of documentation
May 27, 2010
c8b5812
Cleaned up PRUNE_PATHS
May 27, 2010
28bfe9a
Minor updates to the README
May 27, 2010
8cb78a3
Version bump to 0.4.0
May 27, 2010
dacdd3f
Regenerated gemspec for version 0.4.0
May 27, 2010
e9c65b8
Added .gitignore to project
Jun 13, 2010
3da69df
Functionality is refactored into several classes
Jun 13, 2010
45b9b8d
Minor README update
Jun 13, 2010
1e10524
Version bump to 0.5.0
Jun 13, 2010
324bf4f
Regenerated gemspec for version 0.5.0
Jun 13, 2010
7bd3cad
Added RSpec task to Rakefile
Jun 13, 2010
ca40499
Wrapped Options class in grep-fu Module
Jun 13, 2010
25ad7b0
Added specs to GrepFu::Options
Jun 13, 2010
52cdb83
Adding specs to GrepFu::FindBuilder and fixed minor bug
Jun 13, 2010
20d2166
Removed debugging puts again. How does that thing keep getting back …
Jun 14, 2010
1b490fc
Whitespace cleanup
Jun 14, 2010
40fccb1
Added --version feature
Jun 16, 2010
08c5490
Adding specs for find builder
Jun 16, 2010
3db8c0e
Fixed stupid tabs because I forgot to :set et
Jun 16, 2010
037f3ff
Made finder spec less brittle
Jun 16, 2010
89b1bda
Gentler exit when no arguments are provided
Jun 16, 2010
3bfcbb9
Adding specs for runner logic
Jun 16, 2010
de624c7
Adding shebang line to bin file
Jun 16, 2010
34384e0
Updated gemspec for 0.5.0
Jun 16, 2010
b46af89
Regenerated gemspec for version 0.5.0
Jun 16, 2010
78c76f1
Prune docs from list, but add them as option
osake Feb 16, 2012
30ee129
Added example to dox for --single-line feature
Nov 12, 2010
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pkg
20 changes: 20 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright (c) 2009 Eric Budd

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
62 changes: 0 additions & 62 deletions README.markdown

This file was deleted.

181 changes: 181 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
Grep-Fu
=======

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:

grep-fu account_deletion

This will display a list of files which contain the search text:

./app/models/account.rb
./app/controllers/accounts_controller.rb

*NOTE:* Grep-Fu will only work as expected if you are in the root directory of a Rails project!

Installation
------------

Grep-Fu is now a gem:

gem install grep-fu

Often, it can help reduce typing by aliasing the admittedly lengthy "grep-fu" command:

alias g='grep-fu'

Putting this (or a similar shortcut) in your .bashrc or .profile will allow you to use a shorthand version of the command:

g account_deletion

Even Faster
-----------

For more targeted (faster) searches, you can specify one of the following flags to narrow down the search:

a - app
m - app/models
c - app/controllers
v - app/views
h - app/helpers

l - lib

p - public
css - public/stylesheets
js - public/javascripts

s - spec
t - test

vp - vendor/plugins
mig - db/migrate

So to search only your helpers for the term "helpless":

grep-fu h helpless

Multiple word searches and searches containing special regex characters should be surrounded by quotes:

grep-fu s "should be tested"

grep-fu "^[^\?] fishy fishy fishy fish$"

Running grep-fu without parameters will show you what options are available.

Off the Beaten Path
----------------------------

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:

grep-fu lib/tasks troweler

You can even step up out of the current directory. Grep-Fu will use any path shortcuts your underlying OS recognizes.

grep-fu ../../different_rails_project "def similar_method"

grep-fu ~/Projects/roger_tracking last_known_location

I want to see what it found!
----------------------------

For more detail, you can add the '--verbose' flag to command:

grep-fu c budget_dragon --verbose

This will output the filename, line number, and found line.

./app/model/budget.rb:18:
budget_dragon # Bob in accounting's been drinking again

This should be used for fairly narrow searches, as it can produce a whole lot of output.

Thanks go out to [Scotty Moon](http://github.com/scottymoon) for this feature.

Colors
------

If you'd like to see grep-fu's output in color, add the '--color' flag:

grep-fu mig ExtraBiggened --color --verbose

Under most color schemes, the --color option is only useful if --verbose is used as well.

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:

grep-fu mig DoublePlusUnBiggened --no-color

Thanks go out to [Joshua French](http://github.com/osake) for this feature.

Single-Line Output
------------------

Sometimes you need to output all the files grep-fu finds onto a single line; for example, when piping the list into another command:

grep-fu "# Pipe me!" --single-line

The list of files with matches will display on a single line:

./test/unit/calamity_test.rb ./test/unit/havoc_test.rb ./test/unit/mayhem_test.rb...

This is handy if you want to go ahead and load all the files it finds into a text editor.

gvim -p `gx "#TODO"`

Ignoring More Stuff
---------------------

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.

For example, if you have an unusually large set of migrations, you might want to step over them by default. Change the line

PRUNE_PATHS = ['/.svn', '/.git', '/vendor', '/log', '/public', '/tmp', '/coverage']

to

PRUNE_PATHS = ['/.svn', '/.git', '/vendor', '/log', '/public', '/tmp', '/coverage', '/db/migrations']

And migrations will no longer be searched. Note that targeted searches and specified directories always override the PRUNE_PATHS option.

Version Information
-------------------

Passing the '--version' flag to grep-fu will return the current version.

grep-fu --version

returns

grep-fu 0.5.0

Technical mumbo-jumbo
---------------------

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:

* public
* logs
* vendor
* tmp
* coverage
* .svn
* .git

Note that all these directories are still searchable with targeted searches or a directory specification; they're simply not searched by default

Grep-fu also ignores files larger than 100K, which tend to be unsearchable binaries or SQL dumps.

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.

Note on Patches/Pull Requests
-----------------------------

* Fork the project.
* Make your feature addition or bug fix.
* Commit, do not mess with rakefile, version, or history.
(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)
* Send me a pull request. Bonus points for topic branches.

Copyright
---------

Copyright (c) 2010 Eric Budd. See LICENSE for details.
57 changes: 57 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
require 'rubygems'
require 'rake'
require 'spec/rake/spectask'

begin
require 'jeweler'
Jeweler::Tasks.new do |gem|
gem.name = "grep-fu"
gem.summary = %Q{Grep-Fu is a very fast, Rails-oriented command-line helper script for grep.}
gem.description = %Q{Grep-Fu is a very fast, Rails-oriented command-line helper script for grep.}
gem.email = "calamitous@calamitylane.com"
gem.homepage = "http://github.com/Calamitous/grep-fu"
gem.authors = ["Eric Budd"]
end
Jeweler::GemcutterTasks.new
rescue LoadError
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
end

require 'rake/testtask'
Rake::TestTask.new(:test) do |test|
test.libs << 'lib' << 'test'
test.pattern = 'test/**/test_*.rb'
test.verbose = true
end

begin
require 'rcov/rcovtask'
Rcov::RcovTask.new do |test|
test.libs << 'test'
test.pattern = 'test/**/test_*.rb'
test.verbose = true
end
rescue LoadError
task :rcov do
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
end
end

desc "Run all specs"
Spec::Rake::SpecTask.new('run_specs') do |t|
t.spec_files = FileList['spec/**/*.rb']
end

task :test => [:check_dependencies, :run_specs]

task :default => :test

require 'rake/rdoctask'
Rake::RDocTask.new do |rdoc|
version = File.exist?('VERSION') ? File.read('VERSION') : ""

rdoc.rdoc_dir = 'rdoc'
rdoc.title = "grep-fu #{version}"
rdoc.rdoc_files.include('README*')
rdoc.rdoc_files.include('lib/**/*.rb')
end
1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.5.0
5 changes: 5 additions & 0 deletions bin/grep-fu
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env ruby
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
require 'grep-fu'

GrepFu::run!(ARGV)
50 changes: 0 additions & 50 deletions grep-fu

This file was deleted.

Loading