From d22efa6b8cf27dc59273c906743de90a61261c8c Mon Sep 17 00:00:00 2001 From: Joshua French Date: Mon, 1 Feb 2010 15:51:30 -0600 Subject: [PATCH 01/42] Test file to ensure we're not mucking up the repo --- foobaby.txt | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 foobaby.txt diff --git a/foobaby.txt b/foobaby.txt new file mode 100644 index 0000000..e69de29 From 4d2ea248c906c3b04afc17bd530bb2870a357945 Mon Sep 17 00:00:00 2001 From: Joshua French Date: Mon, 1 Feb 2010 15:57:08 -0600 Subject: [PATCH 02/42] Fartin around --- foobaby.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 foobaby.txt diff --git a/foobaby.txt b/foobaby.txt new file mode 100644 index 0000000..9daeafb --- /dev/null +++ b/foobaby.txt @@ -0,0 +1 @@ +test From 9158331dd839757be084c0f0573a7c551a83cae8 Mon Sep 17 00:00:00 2001 From: Joshua French Date: Mon, 1 Feb 2010 16:01:45 -0600 Subject: [PATCH 03/42] Undoing what has been done\! --- foobaby.txt | 1 - 1 file changed, 1 deletion(-) delete mode 100644 foobaby.txt diff --git a/foobaby.txt b/foobaby.txt deleted file mode 100644 index 9daeafb..0000000 --- a/foobaby.txt +++ /dev/null @@ -1 +0,0 @@ -test From 3b01144bf29bcc9e61bd4fe2bc99f7f3e9cd038e Mon Sep 17 00:00:00 2001 From: Eric Budd Date: Sun, 8 Feb 2009 11:38:47 +0800 Subject: [PATCH 04/42] Added option to have colors turned off by default if, say, your laptop's color scheme makes grep-fu unreadable. --- README.markdown => README.md | 14 ++++++++++++++ grep-fu | 9 ++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) rename README.markdown => README.md (79%) diff --git a/README.markdown b/README.md similarity index 79% rename from README.markdown rename to README.md index ecfe933..b22cd8a 100644 --- a/README.markdown +++ b/README.md @@ -53,6 +53,20 @@ This will output the filename, line number, and found line. This should be used 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 to your output: + + grep-fu mig ExtraBiggened --color --verbose + +This will output your results in color. If you'd rather just leave color on all the time, you can change the setting COLOR_ON_BY_DEFAULT to true. If you do this, then you can use the '--no-color' flag to disable the feature: + + grep-fu mig DouplePlusUnBiggened --no-color + +Thanks go out to [Joshua French](http://github.com/osake) for this feature. + + Technical mumbo-jumbo --------------------- diff --git a/grep-fu b/grep-fu index 23b7352..fff004c 100755 --- a/grep-fu +++ b/grep-fu @@ -17,6 +17,7 @@ PATH_REPLACEMENTS = { } PRUNE_PATHS = ['/.svn', '/.git', '/vendor', '/log', '/public/yui', '/tmp', '~'] +COLOR_ON_BY_DEFAULT = false options = '-ril' unless ARGV.size > 0 @@ -29,7 +30,13 @@ end clargs = ARGV verbose = (clargs -= ['--verbose'] if clargs.include?('--verbose')) -color = (clargs -= ['--color'] if clargs.include?('--color')) + +color = (clargs -= ['--color'] if (clargs.include?('--color')) || COLOR_ON_BY_DEFAULT) +if clargs.include?('--no-color') + color = false + color = clargs -= [--no-color] +end + options = '-rin' if verbose options << ' --color=always' if color From f04663fc7f5e30da3ae1d93345c2f39ba29da1c0 Mon Sep 17 00:00:00 2001 From: Eric Budd Date: Tue, 24 Feb 2009 05:00:13 +0800 Subject: [PATCH 05/42] Removed embarrassing misspelling --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b22cd8a..2394918 100644 --- a/README.md +++ b/README.md @@ -62,7 +62,7 @@ If you'd like to see grep-fu's output in color, add the '--color' flag to your o This will output your results in color. If you'd rather just leave color on all the time, you can change the setting COLOR_ON_BY_DEFAULT to true. If you do this, then you can use the '--no-color' flag to disable the feature: - grep-fu mig DouplePlusUnBiggened --no-color + grep-fu mig DoublePlusUnBiggened --no-color Thanks go out to [Joshua French](http://github.com/osake) for this feature. From 930b212f29507e149f601f2b57dc1d304cefd133 Mon Sep 17 00:00:00 2001 From: Eric Budd Date: Fri, 27 Feb 2009 14:23:11 +0800 Subject: [PATCH 06/42] Added 'coverage' to pruned directories --- grep-fu | 2 +- gx | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) create mode 120000 gx diff --git a/grep-fu b/grep-fu index fff004c..9e99b97 100755 --- a/grep-fu +++ b/grep-fu @@ -16,7 +16,7 @@ PATH_REPLACEMENTS = { 'mig' => 'db/migrate' } -PRUNE_PATHS = ['/.svn', '/.git', '/vendor', '/log', '/public/yui', '/tmp', '~'] +PRUNE_PATHS = ['/.svn', '/.git', '/vendor', '/log', '/public/yui', '/tmp', '~', '/coverage'] COLOR_ON_BY_DEFAULT = false options = '-ril' diff --git a/gx b/gx new file mode 120000 index 0000000..22681f7 --- /dev/null +++ b/gx @@ -0,0 +1 @@ +gx \ No newline at end of file From 1c973089892aab58a9bb167129cb69c56593d9d8 Mon Sep 17 00:00:00 2001 From: Eric Budd Date: Sun, 8 Mar 2009 23:36:44 +0800 Subject: [PATCH 07/42] Oops... deleted extraneous file --- gx | 1 - 1 file changed, 1 deletion(-) delete mode 120000 gx diff --git a/gx b/gx deleted file mode 120000 index 22681f7..0000000 --- a/gx +++ /dev/null @@ -1 +0,0 @@ -gx \ No newline at end of file From fb319060b23f454b09006184c9618b50f28d7ef8 Mon Sep 17 00:00:00 2001 From: Eric Budd Date: Sun, 1 Nov 2009 02:59:34 +0800 Subject: [PATCH 08/42] Minor README tweaks --- README.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 2394918..1e0bd2d 100644 --- a/README.md +++ b/README.md @@ -36,11 +36,13 @@ So to search only your helpers for the term "helpless": grep-fu h helpless -Multiple word searches should be surrounded by quotes: +Multiple word searches and searched containing special regex characters should be surrounded by quotes: grep-fu s "it should be tested" -Running grep-fu without a search will show all available options. + grep-fu "^[^\?] fishy fishy fishy fish$" + +Running grep-fu without a search will show you what options are available. I want to see what it found! ---------------------------- @@ -60,7 +62,7 @@ If you'd like to see grep-fu's output in color, add the '--color' flag to your o grep-fu mig ExtraBiggened --color --verbose -This will output your results in color. If you'd rather just leave color on all the time, you can change the setting COLOR_ON_BY_DEFAULT to true. If you do this, then you can use the '--no-color' flag to disable the feature: +This will output your results in color. 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: grep-fu mig DoublePlusUnBiggened --no-color From 6d9bfad377851988f048a2155ba0b69509ea1174 Mon Sep 17 00:00:00 2001 From: Eric Budd Date: Sun, 28 Feb 2010 04:54:26 +0800 Subject: [PATCH 09/42] Grep-fu can now output matches on a single line --- README.md | 4 ++-- grep-fu | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 1e0bd2d..61d5d93 100644 --- a/README.md +++ b/README.md @@ -36,9 +36,9 @@ So to search only your helpers for the term "helpless": grep-fu h helpless -Multiple word searches and searched containing special regex characters should be surrounded by quotes: +Multiple word searches and searches containing special regex characters should be surrounded by quotes: - grep-fu s "it should be tested" + grep-fu s "should be tested" grep-fu "^[^\?] fishy fishy fishy fish$" diff --git a/grep-fu b/grep-fu index 9e99b97..1213ee6 100755 --- a/grep-fu +++ b/grep-fu @@ -21,7 +21,7 @@ COLOR_ON_BY_DEFAULT = false options = '-ril' unless ARGV.size > 0 - puts "\nUsage: #{__FILE__} [findpath] search_string [--verbose]\n + puts "\nUsage: #{__FILE__} [findpath] search_string [--verbose|--single-line]\n Where findpath is one of the following: any literal subdirectory #{PATH_REPLACEMENTS.map { |abbr, txt| " #{abbr} - #{txt}" }.join("\n")}\n\n" @@ -29,9 +29,11 @@ unless ARGV.size > 0 end clargs = ARGV -verbose = (clargs -= ['--verbose'] if clargs.include?('--verbose')) +verbose = (clargs -= ['--verbose'] if clargs.include?('--verbose')) +single_line = (clargs -= ['--single-line'] if clargs.include?('--single-line')) color = (clargs -= ['--color'] if (clargs.include?('--color')) || COLOR_ON_BY_DEFAULT) + if clargs.include?('--no-color') color = false color = clargs -= [--no-color] @@ -51,6 +53,8 @@ if verbose file_and_line = found.slice!(/^.*?:.*?:/) puts "#{file_and_line}\n\t#{found.strip}" end +elsif single_line + puts `#{find_command}`.map { |found| found.chomp }.join(' ') else puts `#{find_command}` end From d825dd4acc120f9aab8def9e288d067e56e628d4 Mon Sep 17 00:00:00 2001 From: Eric Budd Date: Fri, 5 Mar 2010 13:52:35 +0800 Subject: [PATCH 10/42] Documentation includes a section on the single-line feature. This also includes minor cleanups and corrections. --- README.md | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 61d5d93..431f5bb 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,16 @@ Grep-Fu ======= -Grep-Fu is a very fast, Rails-oriented command-line helper script for grep. It's a ruby wrapper for grep for speeding up text searches within the files of a Rails project. The simplest, common usage: +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 "def account_deletion" + grep-fu account_deletion -*IMPORTANT:* Grep-Fu will only work as expected if you are in the root directory of a Rails project! +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! 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. @@ -34,13 +39,13 @@ For more targeted (faster) searches, you can specify one of the following flags So to search only your helpers for the term "helpless": - grep-fu h 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 s "should be tested" - grep-fu "^[^\?] fishy fishy fishy fish$" + grep-fu "^[^\?] fishy fishy fishy fish$" Running grep-fu without a search will show you what options are available. @@ -49,7 +54,7 @@ I want to see what it found! For more detail, you can add the '--verbose' flag to command: - grep-fu c budget_dragon --verbose + grep-fu c budget_dragon --verbose 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,14 +65,24 @@ Colors If you'd like to see grep-fu's output in color, add the '--color' flag to your output: - grep-fu mig ExtraBiggened --color --verbose + grep-fu mig ExtraBiggened --color --verbose -This will output your results in color. 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: +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: - grep-fu mig DoublePlusUnBiggened --no-color + grep-fu mig DoublePlusUnBiggened --no-color Thanks go out to [Joshua French](http://github.com/osake) for this feature. +Single-Line Output +------------------ + +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: + + 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... Technical mumbo-jumbo --------------------- From 18777b80fe0f202feabb6c16380b5795bf49631c Mon Sep 17 00:00:00 2001 From: Eric Budd Date: Fri, 5 Mar 2010 13:56:39 +0800 Subject: [PATCH 11/42] Minor bugfix for disabling color --- grep-fu | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grep-fu b/grep-fu index 1213ee6..f410942 100755 --- a/grep-fu +++ b/grep-fu @@ -35,8 +35,8 @@ single_line = (clargs -= ['--single-line'] if clargs.include?('--single-line')) color = (clargs -= ['--color'] if (clargs.include?('--color')) || COLOR_ON_BY_DEFAULT) if clargs.include?('--no-color') + clargs -= ['--no-color'] color = false - color = clargs -= [--no-color] end options = '-rin' if verbose From 9ef2616ba28ec88c63bee886de3cb0f946d35cf0 Mon Sep 17 00:00:00 2001 From: Eric Budd Date: Fri, 5 Mar 2010 14:00:08 +0800 Subject: [PATCH 12/42] Oh yeah... it's *4* spaces for code blocks in Markdown... --- README.md | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 431f5bb..6d6faf8 100644 --- a/README.md +++ b/README.md @@ -3,12 +3,12 @@ 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 + 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 + ./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! @@ -39,13 +39,13 @@ For more targeted (faster) searches, you can specify one of the following flags So to search only your helpers for the term "helpless": - grep-fu h 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 s "should be tested" - grep-fu "^[^\?] fishy fishy fishy fish$" + grep-fu "^[^\?] fishy fishy fishy fish$" Running grep-fu without a search will show you what options are available. @@ -54,7 +54,7 @@ I want to see what it found! For more detail, you can add the '--verbose' flag to command: - grep-fu c budget_dragon --verbose + grep-fu c budget_dragon --verbose 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. @@ -65,11 +65,11 @@ Colors If you'd like to see grep-fu's output in color, add the '--color' flag to your output: - grep-fu mig ExtraBiggened --color --verbose + grep-fu mig ExtraBiggened --color --verbose 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: - grep-fu mig DoublePlusUnBiggened --no-color + grep-fu mig DoublePlusUnBiggened --no-color Thanks go out to [Joshua French](http://github.com/osake) for this feature. @@ -78,11 +78,11 @@ Single-Line Output 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: - grep-fu "# Pipe me!" --single-line + 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... + ./test/unit/calamity_test.rb ./test/unit/havoc_test.rb ./test/unit/mayhem_test.rb... Technical mumbo-jumbo --------------------- From 525c8ee0a4233f144a0f63bf824e44c4b9ccc120 Mon Sep 17 00:00:00 2001 From: Eric Budd Date: Wed, 12 May 2010 13:25:43 +0800 Subject: [PATCH 13/42] Engemulating grep-fu! --- LICENSE | 20 ++++++++++++++++ README.md => README.rdoc | 13 ++++++++++ Rakefile | 51 ++++++++++++++++++++++++++++++++++++++++ VERSION | 1 + grep-fu => bin/grep-fu | 0 grep-fu.gemspec | 45 +++++++++++++++++++++++++++++++++++ 6 files changed, 130 insertions(+) create mode 100644 LICENSE rename README.md => README.rdoc (86%) create mode 100644 Rakefile create mode 100644 VERSION rename grep-fu => bin/grep-fu (100%) create mode 100644 grep-fu.gemspec diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..80765be --- /dev/null +++ b/LICENSE @@ -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. diff --git a/README.md b/README.rdoc similarity index 86% rename from README.md rename to README.rdoc index 6d6faf8..4a6093c 100644 --- a/README.md +++ b/README.rdoc @@ -91,3 +91,16 @@ Grep-Fu speeds up the searching process by only searching the files you care abo +== Note on Patches/Pull Requests + +* Fork the project. +* Make your feature addition or bug fix. +* Add tests for it. This is important so I don't break it in a + future version unintentionally. +* 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. diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..fcc91a9 --- /dev/null +++ b/Rakefile @@ -0,0 +1,51 @@ +require 'rubygems' +require 'rake' + +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 + +task :test => :check_dependencies + +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 diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..0d91a54 --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +0.3.0 diff --git a/grep-fu b/bin/grep-fu similarity index 100% rename from grep-fu rename to bin/grep-fu diff --git a/grep-fu.gemspec b/grep-fu.gemspec new file mode 100644 index 0000000..b34535b --- /dev/null +++ b/grep-fu.gemspec @@ -0,0 +1,45 @@ +# Generated by jeweler +# DO NOT EDIT THIS FILE DIRECTLY +# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command +# -*- encoding: utf-8 -*- + +Gem::Specification.new do |s| + s.name = %q{grep-fu} + s.version = "0.3.0" + + s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= + s.authors = ["Eric Budd"] + s.date = %q{2010-05-12} + s.default_executable = %q{grep-fu} + s.description = %q{Grep-Fu is a very fast, Rails-oriented command-line helper script for grep.} + s.email = %q{calamitous@calamitylane.com} + s.executables = ["grep-fu"] + s.extra_rdoc_files = [ + "LICENSE", + "README.rdoc" + ] + s.files = [ + "LICENSE", + "README.rdoc", + "Rakefile", + "VERSION", + "bin/grep-fu", + "grep-fu.gemspec" + ] + s.homepage = %q{http://github.com/Calamitous/grep-fu} + s.rdoc_options = ["--charset=UTF-8"] + s.require_paths = ["lib"] + s.rubygems_version = %q{1.3.6} + s.summary = %q{Grep-Fu is a very fast, Rails-oriented command-line helper script for grep.} + + if s.respond_to? :specification_version then + current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION + s.specification_version = 3 + + if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then + else + end + else + end +end + From 3f0993178cf4db363582ec695bbe6afab5b50a99 Mon Sep 17 00:00:00 2001 From: Eric Budd Date: Thu, 13 May 2010 11:29:01 +0800 Subject: [PATCH 14/42] Converted RDoc file back into markdown --- README.rdoc => README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) rename README.rdoc => README.md (97%) diff --git a/README.rdoc b/README.md similarity index 97% rename from README.rdoc rename to README.md index 4a6093c..e62dec8 100644 --- a/README.rdoc +++ b/README.md @@ -91,7 +91,8 @@ Grep-Fu speeds up the searching process by only searching the files you care abo -== Note on Patches/Pull Requests +Note on Patches/Pull Requests +----------------------------- * Fork the project. * Make your feature addition or bug fix. @@ -101,6 +102,7 @@ Grep-Fu speeds up the searching process by only searching the files you care abo (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 +--------- Copyright (c) 2010 Eric Budd. See LICENSE for details. From 998abdd17dbe7eb3f97a77d188abcb4866020a84 Mon Sep 17 00:00:00 2001 From: Eric Budd Date: Thu, 27 May 2010 13:04:20 +0800 Subject: [PATCH 15/42] Added installation instructions to README --- README.md | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e62dec8..39141b1 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,20 @@ This will display a list of files which contain the search text: *NOTE:* Grep-Fu will only work as expected if you are in the root directory of a Rails project! -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. +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 ----------- From bf3f3dd536f3c637431ccfddb4a9fa3df341663e Mon Sep 17 00:00:00 2001 From: Eric Budd Date: Thu, 27 May 2010 13:44:26 +0800 Subject: [PATCH 16/42] Expansion and clarification of documentation --- README.md | 65 ++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 55 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 39141b1..8f803a9 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,20 @@ Multiple word searches and searches containing special regex characters should b grep-fu "^[^\?] fishy fishy fishy fish$" -Running grep-fu without a search will show you what options are available. +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! ---------------------------- @@ -69,18 +82,25 @@ 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. This should be used for fairly narrow searches, as it can produce a whole lot of output. +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 to your output: +If you'd like to see grep-fu's output in color, add the '--color' flag: grep-fu mig ExtraBiggened --color --verbose -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: +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 @@ -89,28 +109,53 @@ Thanks go out to [Joshua French](http://github.com/osake) for this feature. Single-Line Output ------------------ -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: +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... + ./test/unit/calamity_test.rb ./test/unit/havoc_test.rb ./test/unit/mayhem_test.rb... + +Ignoring More Stuff +--------------------- + +When preforming 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'] + +to + + PRUNE_PATHS = ['/.svn', '/.git', '/vendor', '/log', '/db/migrations'] + +And migrations will no longer be searched. Note that targeted searches and specified directories always override the PRUNE_PATHS option. 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 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. +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" 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. + +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. -* Add tests for it. This is important so I don't break it in a - future version unintentionally. * 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. From c8b58124bc5d5f7e4886b1bf54090ef11c5db773 Mon Sep 17 00:00:00 2001 From: Eric Budd Date: Thu, 27 May 2010 13:48:28 +0800 Subject: [PATCH 17/42] Cleaned up PRUNE_PATHS - No longer prunes '~' - Now correctly prunes 'public' --- bin/grep-fu | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/grep-fu b/bin/grep-fu index f410942..937752e 100755 --- a/bin/grep-fu +++ b/bin/grep-fu @@ -16,7 +16,7 @@ PATH_REPLACEMENTS = { 'mig' => 'db/migrate' } -PRUNE_PATHS = ['/.svn', '/.git', '/vendor', '/log', '/public/yui', '/tmp', '~', '/coverage'] +PRUNE_PATHS = ['/.svn', '/.git', '/vendor', '/log', '/public', '/tmp', '/coverage'] COLOR_ON_BY_DEFAULT = false options = '-ril' From 28bfe9a43d7bd126a1e4df225c5af5e13eca3260 Mon Sep 17 00:00:00 2001 From: Eric Budd Date: Thu, 27 May 2010 13:56:11 +0800 Subject: [PATCH 18/42] Minor updates to the README --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 8f803a9..6b5faa4 100644 --- a/README.md +++ b/README.md @@ -120,22 +120,22 @@ The list of files with matches will display on a single line: Ignoring More Stuff --------------------- -When preforming 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. +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'] + PRUNE_PATHS = ['/.svn', '/.git', '/vendor', '/log', '/public', '/tmp', '/coverage'] to - PRUNE_PATHS = ['/.svn', '/.git', '/vendor', '/log', '/db/migrations'] + 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. 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 for grepping which "prunes" the following search directories +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 From 8cb78a3dd6e2a4a35d1b94947cb4a9671ef5d575 Mon Sep 17 00:00:00 2001 From: Eric Budd Date: Thu, 27 May 2010 13:57:31 +0800 Subject: [PATCH 19/42] Version bump to 0.4.0 --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 0d91a54..1d0ba9e 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.3.0 +0.4.0 From dacdd3fc0704d039903a7381a8448e7ebe8f0e48 Mon Sep 17 00:00:00 2001 From: Eric Budd Date: Thu, 27 May 2010 13:58:22 +0800 Subject: [PATCH 20/42] Regenerated gemspec for version 0.4.0 --- grep-fu.gemspec | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/grep-fu.gemspec b/grep-fu.gemspec index b34535b..5f3baf7 100644 --- a/grep-fu.gemspec +++ b/grep-fu.gemspec @@ -5,22 +5,22 @@ Gem::Specification.new do |s| s.name = %q{grep-fu} - s.version = "0.3.0" + s.version = "0.4.0" s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= s.authors = ["Eric Budd"] - s.date = %q{2010-05-12} + s.date = %q{2010-05-27} s.default_executable = %q{grep-fu} s.description = %q{Grep-Fu is a very fast, Rails-oriented command-line helper script for grep.} s.email = %q{calamitous@calamitylane.com} s.executables = ["grep-fu"] s.extra_rdoc_files = [ "LICENSE", - "README.rdoc" + "README.md" ] s.files = [ "LICENSE", - "README.rdoc", + "README.md", "Rakefile", "VERSION", "bin/grep-fu", From e9c65b821f34733c59077823f37bcf411ca1a4c3 Mon Sep 17 00:00:00 2001 From: Eric Budd Date: Mon, 14 Jun 2010 02:19:23 +0800 Subject: [PATCH 21/42] Added .gitignore to project --- .gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5fff1d9 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +pkg From 3da69dfcd47b234b6223821ad88cd9c69f17bcff Mon Sep 17 00:00:00 2001 From: Eric Budd Date: Mon, 14 Jun 2010 02:25:55 +0800 Subject: [PATCH 22/42] Functionality is refactored into several classes --- bin/grep-fu | 65 +++---------------------------------- lib/grep-fu.rb | 27 +++++++++++++++ lib/grep-fu/find_builder.rb | 18 ++++++++++ lib/grep-fu/options.rb | 54 ++++++++++++++++++++++++++++++ 4 files changed, 103 insertions(+), 61 deletions(-) create mode 100644 lib/grep-fu.rb create mode 100644 lib/grep-fu/find_builder.rb create mode 100644 lib/grep-fu/options.rb diff --git a/bin/grep-fu b/bin/grep-fu index 937752e..f31d697 100755 --- a/bin/grep-fu +++ b/bin/grep-fu @@ -1,61 +1,4 @@ -#!/usr/bin/env ruby - -PATH_REPLACEMENTS = { - 'a' => 'app', - 'c' => 'app/controllers', - 'h' => 'app/helpers', - 'm' => 'app/models', - 'v' => 'app/views', - 'l' => 'lib', - 'p' => 'public', - 'css' => 'public/stylesheets', - 'js' => 'public/javascripts', - 't' => 'test', - 's' => 'spec', - 'vp' => 'vendor/plugins', - 'mig' => 'db/migrate' - } - -PRUNE_PATHS = ['/.svn', '/.git', '/vendor', '/log', '/public', '/tmp', '/coverage'] -COLOR_ON_BY_DEFAULT = false -options = '-ril' - -unless ARGV.size > 0 - puts "\nUsage: #{__FILE__} [findpath] search_string [--verbose|--single-line]\n - Where findpath is one of the following: - any literal subdirectory -#{PATH_REPLACEMENTS.map { |abbr, txt| " #{abbr} - #{txt}" }.join("\n")}\n\n" - exit -end - -clargs = ARGV - -verbose = (clargs -= ['--verbose'] if clargs.include?('--verbose')) -single_line = (clargs -= ['--single-line'] if clargs.include?('--single-line')) -color = (clargs -= ['--color'] if (clargs.include?('--color')) || COLOR_ON_BY_DEFAULT) - -if clargs.include?('--no-color') - clargs -= ['--no-color'] - color = false -end - -options = '-rin' if verbose -options << ' --color=always' if color - -search_criteria = clargs.last -file_path = clargs.size == 2 ? PATH_REPLACEMENTS[clargs.first] || clargs.first : './' -delicious_prunes = PRUNE_PATHS ? "-path '*#{PRUNE_PATHS.join("' -prune -o -path *'")}' -prune -o" : '' - -find_command = "find #{file_path} #{delicious_prunes} \\( -size -100000c -type f \\) -print0 | xargs -0 grep #{options} \"#{search_criteria}\"" - -if verbose - `#{find_command}`.each_line do |found| - file_and_line = found.slice!(/^.*?:.*?:/) - puts "#{file_and_line}\n\t#{found.strip}" - end -elsif single_line - puts `#{find_command}`.map { |found| found.chomp }.join(' ') -else - puts `#{find_command}` -end - +$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib') +require 'grep-fu' + +GrepFu::run!(ARGV) diff --git a/lib/grep-fu.rb b/lib/grep-fu.rb new file mode 100644 index 0000000..59498f4 --- /dev/null +++ b/lib/grep-fu.rb @@ -0,0 +1,27 @@ +require 'grep-fu/options' +require 'grep-fu/find_builder' + +module GrepFu + def self.run!(args = []) + unless args.size > 0 + puts Options.usage(__FILE__) + exit + end + + options = Options.new(args) + + find_command = FindBuilder.find_command(options) + puts find_command + + if options.verbose + `#{find_command}`.each_line do |found| + file_and_line = found.slice!(/^.*?:.*?:/) + puts "#{file_and_line}\n\t#{found.strip}" + end + elsif options.single_line + puts `#{find_command}`.map { |found| found.chomp }.join(' ') + else + puts `#{find_command}` + end + end +end diff --git a/lib/grep-fu/find_builder.rb b/lib/grep-fu/find_builder.rb new file mode 100644 index 0000000..36a2b17 --- /dev/null +++ b/lib/grep-fu/find_builder.rb @@ -0,0 +1,18 @@ +module GrepFu + class FindBuilder + PRUNE_PATHS = ['/.svn', '/.git', '/vendor', '/log', '/public', '/tmp', '/coverage'] + + def self.find_command(options) + delicious_prunes = "-path '*#{PRUNE_PATHS.join("' -prune -o -path *'")}' -prune -o" + + [ + 'find', + options.file_path, + delicious_prunes, + "\\( -size -100000c -type f \\) -print0 | xargs -0 grep", + options.to_s, + "\"#{options.search_criteria}\"" + ].join(' ') + end + end +end diff --git a/lib/grep-fu/options.rb b/lib/grep-fu/options.rb new file mode 100644 index 0000000..da1162c --- /dev/null +++ b/lib/grep-fu/options.rb @@ -0,0 +1,54 @@ +class Options + attr_reader :verbose, :single_line, :color, :search_criteria, :file_path + + PATH_REPLACEMENTS = { + 'a' => 'app', + 'c' => 'app/controllers', + 'h' => 'app/helpers', + 'm' => 'app/models', + 'v' => 'app/views', + 'l' => 'lib', + 'p' => 'public', + 'css' => 'public/stylesheets', + 'js' => 'public/javascripts', + 't' => 'test', + 's' => 'spec', + 'vp' => 'vendor/plugins', + 'mig' => 'db/migrate' + } + + COLOR_ON_BY_DEFAULT = false + + def self.usage(file) + lines = ['', + "Usage: #{file} [findpath] search_string [--verbose|--single-line]\n", + " Where findpath is one of the following:", + " any literal subdirectory", + Options::PATH_REPLACEMENTS.map { |abbr, txt| " #{abbr} - #{txt}" }.join("\n"), + "\n\n" + ] + + lines.join("\n") + end + + def initialize(args) + @verbose = (args -= ['--verbose'] if args.include?('--verbose')) + @single_line = (args -= ['--single-line'] if args.include?('--single-line')) + + @color = (args -= ['--color'] if (args.include?('--color')) || COLOR_ON_BY_DEFAULT) + if args.include?('--no-color') + args -= ['--no-color'] + @color = false + end + + @search_criteria = args.last + @file_path = args.size == 2 ? PATH_REPLACEMENTS[args.first] || args.first : './' + end + + def to_s + options = @verbose ? '-rin' : '-ril' + options << ' --color=always' if @color + options + end + +end From 45b9b8dfb07bef9b2f114420da8338e9b60b6ece Mon Sep 17 00:00:00 2001 From: Eric Budd Date: Mon, 14 Jun 2010 02:26:57 +0800 Subject: [PATCH 23/42] Minor README update --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6b5faa4..d79bf4b 100644 --- a/README.md +++ b/README.md @@ -147,7 +147,7 @@ Grep-Fu speeds up the searching process by only searching the files you care abo 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. +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. From 1e1052400be8171fd43dbc352d66c74966ca7b56 Mon Sep 17 00:00:00 2001 From: Eric Budd Date: Mon, 14 Jun 2010 02:30:56 +0800 Subject: [PATCH 24/42] Version bump to 0.5.0 --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 1d0ba9e..8f0916f 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.4.0 +0.5.0 From 324bf4fa9b60a6a4d381b58864c9a6852c994413 Mon Sep 17 00:00:00 2001 From: Eric Budd Date: Mon, 14 Jun 2010 02:34:07 +0800 Subject: [PATCH 25/42] Regenerated gemspec for version 0.5.0 --- grep-fu.gemspec | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/grep-fu.gemspec b/grep-fu.gemspec index 5f3baf7..eb57a17 100644 --- a/grep-fu.gemspec +++ b/grep-fu.gemspec @@ -1,15 +1,17 @@ # Generated by jeweler +# re +# # DO NOT EDIT THIS FILE DIRECTLY # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command # -*- encoding: utf-8 -*- Gem::Specification.new do |s| s.name = %q{grep-fu} - s.version = "0.4.0" + s.version = "0.5.0" s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= s.authors = ["Eric Budd"] - s.date = %q{2010-05-27} + s.date = %q{2010-06-13} s.default_executable = %q{grep-fu} s.description = %q{Grep-Fu is a very fast, Rails-oriented command-line helper script for grep.} s.email = %q{calamitous@calamitylane.com} @@ -19,12 +21,15 @@ Gem::Specification.new do |s| "README.md" ] s.files = [ - "LICENSE", + "LICENSE", "README.md", "Rakefile", "VERSION", "bin/grep-fu", - "grep-fu.gemspec" + "grep-fu.gemspec", + "lib/grep-fu.rb", + "lib/grep-fu/find_builder.rb", + "lib/grep-fu/options.rb" ] s.homepage = %q{http://github.com/Calamitous/grep-fu} s.rdoc_options = ["--charset=UTF-8"] From 7bd3cad8ce2958054517dc79f9827b0c93470035 Mon Sep 17 00:00:00 2001 From: Eric Budd Date: Mon, 14 Jun 2010 04:06:34 +0800 Subject: [PATCH 26/42] Added RSpec task to Rakefile --- Rakefile | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Rakefile b/Rakefile index fcc91a9..e3fc80f 100644 --- a/Rakefile +++ b/Rakefile @@ -1,5 +1,6 @@ require 'rubygems' require 'rake' +require 'spec/rake/spectask' begin require 'jeweler' @@ -36,7 +37,12 @@ rescue LoadError end end -task :test => :check_dependencies +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 From ca40499d3016c94fbccac2476e7dddc190c9090f Mon Sep 17 00:00:00 2001 From: Eric Budd Date: Mon, 14 Jun 2010 04:21:16 +0800 Subject: [PATCH 27/42] Wrapped Options class in grep-fu Module --- lib/grep-fu/options.rb | 90 +++++++++++++++++++++--------------------- 1 file changed, 46 insertions(+), 44 deletions(-) diff --git a/lib/grep-fu/options.rb b/lib/grep-fu/options.rb index da1162c..fc35ae8 100644 --- a/lib/grep-fu/options.rb +++ b/lib/grep-fu/options.rb @@ -1,54 +1,56 @@ -class Options - attr_reader :verbose, :single_line, :color, :search_criteria, :file_path - - PATH_REPLACEMENTS = { - 'a' => 'app', - 'c' => 'app/controllers', - 'h' => 'app/helpers', - 'm' => 'app/models', - 'v' => 'app/views', - 'l' => 'lib', - 'p' => 'public', - 'css' => 'public/stylesheets', - 'js' => 'public/javascripts', - 't' => 'test', - 's' => 'spec', - 'vp' => 'vendor/plugins', - 'mig' => 'db/migrate' - } - - COLOR_ON_BY_DEFAULT = false - - def self.usage(file) - lines = ['', - "Usage: #{file} [findpath] search_string [--verbose|--single-line]\n", +module GrepFu + class Options + attr_reader :verbose, :single_line, :color, :search_criteria, :file_path + + PATH_REPLACEMENTS = { + 'a' => 'app', + 'c' => 'app/controllers', + 'h' => 'app/helpers', + 'm' => 'app/models', + 'v' => 'app/views', + 'l' => 'lib', + 'p' => 'public', + 'css' => 'public/stylesheets', + 'js' => 'public/javascripts', + 't' => 'test', + 's' => 'spec', + 'vp' => 'vendor/plugins', + 'mig' => 'db/migrate' + } + + COLOR_ON_BY_DEFAULT = false + + def self.usage(file) + lines = ['', + "Usage: #{file} [findpath] search_string [--verbose|--single-line]\n", " Where findpath is one of the following:", - " any literal subdirectory", - Options::PATH_REPLACEMENTS.map { |abbr, txt| " #{abbr} - #{txt}" }.join("\n"), + " any literal subdirectory", + Options::PATH_REPLACEMENTS.map { |abbr, txt| " #{abbr} - #{txt}" }.join("\n"), "\n\n" - ] + ] - lines.join("\n") - end + lines.join("\n") + end + + def initialize(args) + @verbose = (args -= ['--verbose'] if args.include?('--verbose')) + @single_line = (args -= ['--single-line'] if args.include?('--single-line')) - def initialize(args) - @verbose = (args -= ['--verbose'] if args.include?('--verbose')) - @single_line = (args -= ['--single-line'] if args.include?('--single-line')) + @color = (args -= ['--color'] if (args.include?('--color')) || COLOR_ON_BY_DEFAULT) + if args.include?('--no-color') + args -= ['--no-color'] + @color = false + end - @color = (args -= ['--color'] if (args.include?('--color')) || COLOR_ON_BY_DEFAULT) - if args.include?('--no-color') - args -= ['--no-color'] - @color = false + @search_criteria = args.last + @file_path = args.size == 2 ? PATH_REPLACEMENTS[args.first] || args.first : './' end - @search_criteria = args.last - @file_path = args.size == 2 ? PATH_REPLACEMENTS[args.first] || args.first : './' - end + def to_s + options = @verbose ? '-rin' : '-ril' + options << ' --color=always' if @color + options + end - def to_s - options = @verbose ? '-rin' : '-ril' - options << ' --color=always' if @color - options end - end From 25ad7b0e8d8d5e8e43adc0c5126800a6345d8303 Mon Sep 17 00:00:00 2001 From: Eric Budd Date: Mon, 14 Jun 2010 04:22:11 +0800 Subject: [PATCH 28/42] Added specs to GrepFu::Options --- spec/options_spec.rb | 55 ++++++++++++++++++++++++++++++++++++++++++++ spec/spec_helper.rb | 6 +++++ 2 files changed, 61 insertions(+) create mode 100644 spec/options_spec.rb create mode 100644 spec/spec_helper.rb diff --git a/spec/options_spec.rb b/spec/options_spec.rb new file mode 100644 index 0000000..1935c45 --- /dev/null +++ b/spec/options_spec.rb @@ -0,0 +1,55 @@ +require 'grep-fu/options' +require 'spec/spec_helper' + +describe GrepFu::Options do + it "should instantiate correctly" do + GrepFu::Options.new([]) + end + + it "should set the verbose option to true, if provided" do + GrepFu::Options.new(['--verbose']).verbose.should be_true + end + + it "should set the single-line option to true, if provided" do + GrepFu::Options.new(['--single-line']).single_line.should be_true + end + + it "should set the color option to true, if provided" do + GrepFu::Options.new(['--color']).color.should be_true + end + + it "should default to no color" do + GrepFu::Options.new([]).color.should be_false + end + + it "should allow color to be disabled from the command line" do + GrepFu::Options.new(['--no_color']).color.should be_false + end + + it "should change color default based on constant" do + silence_warnings { GrepFu::Options::COLOR_ON_BY_DEFAULT = true } + GrepFu::Options.new([]).color.should be_true + end + + it "should allow color to be disabled from the command line when default is color=true" do + silence_warnings { GrepFu::Options::COLOR_ON_BY_DEFAULT = true } + GrepFu::Options.new(['--no-color']).color.should be_false + end + + it "should set the search criteria to the last non-option flag in the list" do + GrepFu::Options.new(%w{offer}).search_criteria.should == 'offer' + GrepFu::Options.new(%w{a help --color}).search_criteria.should == 'help' + GrepFu::Options.new(%w{lib/tasks unrake --verbose --color}).search_criteria.should == 'unrake' + end + + it "should expand the file_path to one of the replacement variables, if found" do + GrepFu::Options.new(%w{a value}).file_path.should == 'app' + GrepFu::Options.new(%w{s hoozits}).file_path.should == 'spec' + GrepFu::Options.new(%w{mig down --color}).file_path.should == 'db/migrate' + end + + it "should accept an explicit find path, if provided" do + GrepFu::Options.new(%w{lib/tasks value}).file_path.should == 'lib/tasks' + end + +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..553f931 --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,6 @@ +def silence_warnings + old_verbose, $VERBOSE = $VERBOSE, nil + yield +ensure + $VERBOSE = old_verbose +end From 52cdb83d8d2691a260ae610f31b4112c2372e646 Mon Sep 17 00:00:00 2001 From: Eric Budd Date: Mon, 14 Jun 2010 04:23:58 +0800 Subject: [PATCH 29/42] Adding specs to GrepFu::FindBuilder and fixed minor bug --- lib/grep-fu/find_builder.rb | 5 ++++- spec/find_builder_spec.rb | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 spec/find_builder_spec.rb diff --git a/lib/grep-fu/find_builder.rb b/lib/grep-fu/find_builder.rb index 36a2b17..5a28ce5 100644 --- a/lib/grep-fu/find_builder.rb +++ b/lib/grep-fu/find_builder.rb @@ -2,8 +2,11 @@ module GrepFu class FindBuilder PRUNE_PATHS = ['/.svn', '/.git', '/vendor', '/log', '/public', '/tmp', '/coverage'] + def self.delicious_prunes + "-path '*#{PRUNE_PATHS.join("' -prune -o -path '*")}' -prune -o" + end + def self.find_command(options) - delicious_prunes = "-path '*#{PRUNE_PATHS.join("' -prune -o -path *'")}' -prune -o" [ 'find', diff --git a/spec/find_builder_spec.rb b/spec/find_builder_spec.rb new file mode 100644 index 0000000..e2bedc3 --- /dev/null +++ b/spec/find_builder_spec.rb @@ -0,0 +1,15 @@ +require 'grep-fu/find_builder' +require 'spec/spec_helper' + +describe GrepFu::FindBuilder do + it "should create command-line options for pruning path" do + silence_warnings { GrepFu::FindBuilder::PRUNE_PATHS = ['/pruney'] } + GrepFu::FindBuilder.delicious_prunes.should == "-path '*/pruney' -prune -o" + end + + it "should create command-line options for multiple pruning paths" do + silence_warnings { GrepFu::FindBuilder::PRUNE_PATHS = ['/pruney', '/apply'] } + GrepFu::FindBuilder.delicious_prunes.should == "-path '*/pruney' -prune -o -path '*/apply' -prune -o" + end +end + From 20d2166d5cde10b5330401dd695ce42ded2068d3 Mon Sep 17 00:00:00 2001 From: Eric Budd Date: Mon, 14 Jun 2010 13:06:27 +0800 Subject: [PATCH 30/42] Removed debugging puts again. How does that thing keep getting back in there? --- lib/grep-fu.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/grep-fu.rb b/lib/grep-fu.rb index 59498f4..e8383a5 100644 --- a/lib/grep-fu.rb +++ b/lib/grep-fu.rb @@ -11,7 +11,6 @@ def self.run!(args = []) options = Options.new(args) find_command = FindBuilder.find_command(options) - puts find_command if options.verbose `#{find_command}`.each_line do |found| From 1b490fc5489e5e8a7fdc8a277a21b1fb1781252e Mon Sep 17 00:00:00 2001 From: Eric Budd Date: Mon, 14 Jun 2010 13:07:03 +0800 Subject: [PATCH 31/42] Whitespace cleanup --- lib/grep-fu/find_builder.rb | 1 - lib/grep-fu/options.rb | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/grep-fu/find_builder.rb b/lib/grep-fu/find_builder.rb index 5a28ce5..6939d57 100644 --- a/lib/grep-fu/find_builder.rb +++ b/lib/grep-fu/find_builder.rb @@ -7,7 +7,6 @@ def self.delicious_prunes end def self.find_command(options) - [ 'find', options.file_path, diff --git a/lib/grep-fu/options.rb b/lib/grep-fu/options.rb index fc35ae8..f426ac2 100644 --- a/lib/grep-fu/options.rb +++ b/lib/grep-fu/options.rb @@ -23,7 +23,7 @@ class Options def self.usage(file) lines = ['', "Usage: #{file} [findpath] search_string [--verbose|--single-line]\n", - " Where findpath is one of the following:", + " Where findpath is one of the following:", " any literal subdirectory", Options::PATH_REPLACEMENTS.map { |abbr, txt| " #{abbr} - #{txt}" }.join("\n"), "\n\n" From 40fccb129e8cf9dc1a9f5bb5e56794aa49b5a1fc Mon Sep 17 00:00:00 2001 From: Eric Budd Date: Wed, 16 Jun 2010 10:47:22 +0800 Subject: [PATCH 32/42] Added --version feature --- README.md | 11 +++++++++++ lib/grep-fu/options.rb | 5 +++++ 2 files changed, 16 insertions(+) diff --git a/README.md b/README.md index d79bf4b..be0c2f3 100644 --- a/README.md +++ b/README.md @@ -132,6 +132,17 @@ to 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 --------------------- diff --git a/lib/grep-fu/options.rb b/lib/grep-fu/options.rb index f426ac2..19ae752 100644 --- a/lib/grep-fu/options.rb +++ b/lib/grep-fu/options.rb @@ -33,6 +33,11 @@ def self.usage(file) end def initialize(args) + if args.include?('--version') + puts "grep-fu #{File.read(File.join(File.dirname(__FILE__), '..', '..', 'VERSION'))}" + exit(0) + end + @verbose = (args -= ['--verbose'] if args.include?('--verbose')) @single_line = (args -= ['--single-line'] if args.include?('--single-line')) From 08c5490b2c39e4879372a415380b5b03f6465a2d Mon Sep 17 00:00:00 2001 From: Eric Budd Date: Wed, 16 Jun 2010 11:05:23 +0800 Subject: [PATCH 33/42] Adding specs for find builder --- spec/find_builder_spec.rb | 61 +++++++++++++++++++++++++++++++++------ 1 file changed, 52 insertions(+), 9 deletions(-) diff --git a/spec/find_builder_spec.rb b/spec/find_builder_spec.rb index e2bedc3..40ac901 100644 --- a/spec/find_builder_spec.rb +++ b/spec/find_builder_spec.rb @@ -2,14 +2,57 @@ require 'spec/spec_helper' describe GrepFu::FindBuilder do - it "should create command-line options for pruning path" do - silence_warnings { GrepFu::FindBuilder::PRUNE_PATHS = ['/pruney'] } - GrepFu::FindBuilder.delicious_prunes.should == "-path '*/pruney' -prune -o" - end - - it "should create command-line options for multiple pruning paths" do - silence_warnings { GrepFu::FindBuilder::PRUNE_PATHS = ['/pruney', '/apply'] } - GrepFu::FindBuilder.delicious_prunes.should == "-path '*/pruney' -prune -o -path '*/apply' -prune -o" - end + describe "#delicious_prunes" do + it "should create command-line options for pruning path" do + silence_warnings { GrepFu::FindBuilder::PRUNE_PATHS = ['/pruney'] } + GrepFu::FindBuilder.delicious_prunes.should == "-path '*/pruney' -prune -o" + end + + it "should create command-line options for multiple pruning paths" do + silence_warnings { GrepFu::FindBuilder::PRUNE_PATHS = ['/pruney', '/apply'] } + GrepFu::FindBuilder.delicious_prunes.should == "-path '*/pruney' -prune -o -path '*/apply' -prune -o" + end + end + + describe "#find_command" do + before(:each) do + GrepFu::FindBuilder.stub!(:delicious_prunes).and_return('prune_list') + @options = mock(Object, + :file_path => 'path', + :to_s => 'str_opts', + :search_criteria => 'crits') + @find_command = GrepFu::FindBuilder.find_command(@options) + end + + it "should start with the find command" do + @find_command.should =~ /^find\s/ + end + + it "should contain the file path" do + @find_command.should =~ /\spath\s/ + end + + it "should contain all the pruned directories" do + @find_command.should =~ /\sprune_list\s/ + end + + it "should contain a blob of bash muck" do + @find_command.should =~ /\s.. -size -100000c -type f .. -print0 | xargs -0 grep\s/ + end + + it "should contain the options" do + @find_command.should =~ /\sstr_opts\s/ + end + + it "should end with the quoted search criteria" do + @find_command.should =~ /\s"crits"$/ + end + + it "should stitch together a long, long find command" do + @find_command.should =~ /find path prune_list \\{ -size -100000c -type f \\} -print0 | xargs -0 grep str_opts \"crits\"/ + end + + end + end From 3db8c0e5e8aa304ce9eb82c398b1e9f2cd01784f Mon Sep 17 00:00:00 2001 From: Eric Budd Date: Wed, 16 Jun 2010 11:56:40 +0800 Subject: [PATCH 34/42] Fixed stupid tabs because I forgot to :set et --- lib/grep-fu.rb | 36 +++++------ lib/grep-fu/find_builder.rb | 32 +++++----- lib/grep-fu/options.rb | 118 ++++++++++++++++++------------------ spec/options_spec.rb | 98 +++++++++++++++--------------- spec/spec_helper.rb | 6 +- 5 files changed, 145 insertions(+), 145 deletions(-) diff --git a/lib/grep-fu.rb b/lib/grep-fu.rb index e8383a5..6714b69 100644 --- a/lib/grep-fu.rb +++ b/lib/grep-fu.rb @@ -2,25 +2,25 @@ require 'grep-fu/find_builder' module GrepFu - def self.run!(args = []) - unless args.size > 0 - puts Options.usage(__FILE__) - exit - end + def self.run!(args = []) + unless args.size > 0 + puts Options.usage(__FILE__) + exit + end - options = Options.new(args) + options = Options.new(args) - find_command = FindBuilder.find_command(options) + find_command = FindBuilder.find_command(options) - if options.verbose - `#{find_command}`.each_line do |found| - file_and_line = found.slice!(/^.*?:.*?:/) - puts "#{file_and_line}\n\t#{found.strip}" - end - elsif options.single_line - puts `#{find_command}`.map { |found| found.chomp }.join(' ') - else - puts `#{find_command}` - end - end + if options.verbose + `#{find_command}`.each_line do |found| + file_and_line = found.slice!(/^.*?:.*?:/) + puts "#{file_and_line}\n\t#{found.strip}" + end + elsif options.single_line + puts `#{find_command}`.map { |found| found.chomp }.join(' ') + else + puts `#{find_command}` + end + end end diff --git a/lib/grep-fu/find_builder.rb b/lib/grep-fu/find_builder.rb index 6939d57..d73ae80 100644 --- a/lib/grep-fu/find_builder.rb +++ b/lib/grep-fu/find_builder.rb @@ -1,20 +1,20 @@ module GrepFu - class FindBuilder - PRUNE_PATHS = ['/.svn', '/.git', '/vendor', '/log', '/public', '/tmp', '/coverage'] + class FindBuilder + PRUNE_PATHS = ['/.svn', '/.git', '/vendor', '/log', '/public', '/tmp', '/coverage'] - def self.delicious_prunes - "-path '*#{PRUNE_PATHS.join("' -prune -o -path '*")}' -prune -o" - end + def self.delicious_prunes + "-path '*#{PRUNE_PATHS.join("' -prune -o -path '*")}' -prune -o" + end - def self.find_command(options) - [ - 'find', - options.file_path, - delicious_prunes, - "\\( -size -100000c -type f \\) -print0 | xargs -0 grep", - options.to_s, - "\"#{options.search_criteria}\"" - ].join(' ') - end - end + def self.find_command(options) + [ + 'find', + options.file_path, + delicious_prunes, + "\\( -size -100000c -type f \\) -print0 | xargs -0 grep", + options.to_s, + "\"#{options.search_criteria}\"" + ].join(' ') + end + end end diff --git a/lib/grep-fu/options.rb b/lib/grep-fu/options.rb index 19ae752..c7e66ee 100644 --- a/lib/grep-fu/options.rb +++ b/lib/grep-fu/options.rb @@ -1,61 +1,61 @@ module GrepFu - class Options - attr_reader :verbose, :single_line, :color, :search_criteria, :file_path - - PATH_REPLACEMENTS = { - 'a' => 'app', - 'c' => 'app/controllers', - 'h' => 'app/helpers', - 'm' => 'app/models', - 'v' => 'app/views', - 'l' => 'lib', - 'p' => 'public', - 'css' => 'public/stylesheets', - 'js' => 'public/javascripts', - 't' => 'test', - 's' => 'spec', - 'vp' => 'vendor/plugins', - 'mig' => 'db/migrate' - } - - COLOR_ON_BY_DEFAULT = false - - def self.usage(file) - lines = ['', - "Usage: #{file} [findpath] search_string [--verbose|--single-line]\n", - " Where findpath is one of the following:", - " any literal subdirectory", - Options::PATH_REPLACEMENTS.map { |abbr, txt| " #{abbr} - #{txt}" }.join("\n"), - "\n\n" - ] - - lines.join("\n") - end - - def initialize(args) - if args.include?('--version') - puts "grep-fu #{File.read(File.join(File.dirname(__FILE__), '..', '..', 'VERSION'))}" - exit(0) - end - - @verbose = (args -= ['--verbose'] if args.include?('--verbose')) - @single_line = (args -= ['--single-line'] if args.include?('--single-line')) - - @color = (args -= ['--color'] if (args.include?('--color')) || COLOR_ON_BY_DEFAULT) - if args.include?('--no-color') - args -= ['--no-color'] - @color = false - end - - @search_criteria = args.last - @file_path = args.size == 2 ? PATH_REPLACEMENTS[args.first] || args.first : './' - end - - def to_s - options = @verbose ? '-rin' : '-ril' - options << ' --color=always' if @color - options - end - - end + class Options + attr_reader :verbose, :single_line, :color, :search_criteria, :file_path + + PATH_REPLACEMENTS = { + 'a' => 'app', + 'c' => 'app/controllers', + 'h' => 'app/helpers', + 'm' => 'app/models', + 'v' => 'app/views', + 'l' => 'lib', + 'p' => 'public', + 'css' => 'public/stylesheets', + 'js' => 'public/javascripts', + 't' => 'test', + 's' => 'spec', + 'vp' => 'vendor/plugins', + 'mig' => 'db/migrate' + } + + COLOR_ON_BY_DEFAULT = false + + def self.usage(file) + lines = ['', + "Usage: #{file} [findpath] search_string [--verbose|--single-line]\n", + " Where findpath is one of the following:", + " any literal subdirectory", + Options::PATH_REPLACEMENTS.map { |abbr, txt| " #{abbr} - #{txt}" }.join("\n"), + "\n\n" + ] + + lines.join("\n") + end + + def initialize(args) + if args.include?('--version') + puts "grep-fu #{File.read(File.join(File.dirname(__FILE__), '..', '..', 'VERSION'))}" + exit(0) + end + + @verbose = (args -= ['--verbose'] if args.include?('--verbose')) + @single_line = (args -= ['--single-line'] if args.include?('--single-line')) + + @color = (args -= ['--color'] if (args.include?('--color')) || COLOR_ON_BY_DEFAULT) + if args.include?('--no-color') + args -= ['--no-color'] + @color = false + end + + @search_criteria = args.last + @file_path = args.size == 2 ? PATH_REPLACEMENTS[args.first] || args.first : './' + end + + def to_s + options = @verbose ? '-rin' : '-ril' + options << ' --color=always' if @color + options + end + + end end diff --git a/spec/options_spec.rb b/spec/options_spec.rb index 1935c45..483c103 100644 --- a/spec/options_spec.rb +++ b/spec/options_spec.rb @@ -2,54 +2,54 @@ require 'spec/spec_helper' describe GrepFu::Options do - it "should instantiate correctly" do - GrepFu::Options.new([]) - end - - it "should set the verbose option to true, if provided" do - GrepFu::Options.new(['--verbose']).verbose.should be_true - end - - it "should set the single-line option to true, if provided" do - GrepFu::Options.new(['--single-line']).single_line.should be_true - end - - it "should set the color option to true, if provided" do - GrepFu::Options.new(['--color']).color.should be_true - end - - it "should default to no color" do - GrepFu::Options.new([]).color.should be_false - end - - it "should allow color to be disabled from the command line" do - GrepFu::Options.new(['--no_color']).color.should be_false - end - - it "should change color default based on constant" do - silence_warnings { GrepFu::Options::COLOR_ON_BY_DEFAULT = true } - GrepFu::Options.new([]).color.should be_true - end - - it "should allow color to be disabled from the command line when default is color=true" do - silence_warnings { GrepFu::Options::COLOR_ON_BY_DEFAULT = true } - GrepFu::Options.new(['--no-color']).color.should be_false - end - - it "should set the search criteria to the last non-option flag in the list" do - GrepFu::Options.new(%w{offer}).search_criteria.should == 'offer' - GrepFu::Options.new(%w{a help --color}).search_criteria.should == 'help' - GrepFu::Options.new(%w{lib/tasks unrake --verbose --color}).search_criteria.should == 'unrake' - end - - it "should expand the file_path to one of the replacement variables, if found" do - GrepFu::Options.new(%w{a value}).file_path.should == 'app' - GrepFu::Options.new(%w{s hoozits}).file_path.should == 'spec' - GrepFu::Options.new(%w{mig down --color}).file_path.should == 'db/migrate' - end - - it "should accept an explicit find path, if provided" do - GrepFu::Options.new(%w{lib/tasks value}).file_path.should == 'lib/tasks' - end + it "should instantiate correctly" do + GrepFu::Options.new([]) + end + + it "should set the verbose option to true, if provided" do + GrepFu::Options.new(['--verbose']).verbose.should be_true + end + + it "should set the single-line option to true, if provided" do + GrepFu::Options.new(['--single-line']).single_line.should be_true + end + + it "should set the color option to true, if provided" do + GrepFu::Options.new(['--color']).color.should be_true + end + + it "should default to no color" do + GrepFu::Options.new([]).color.should be_false + end + + it "should allow color to be disabled from the command line" do + GrepFu::Options.new(['--no_color']).color.should be_false + end + + it "should change color default based on constant" do + silence_warnings { GrepFu::Options::COLOR_ON_BY_DEFAULT = true } + GrepFu::Options.new([]).color.should be_true + end + + it "should allow color to be disabled from the command line when default is color=true" do + silence_warnings { GrepFu::Options::COLOR_ON_BY_DEFAULT = true } + GrepFu::Options.new(['--no-color']).color.should be_false + end + + it "should set the search criteria to the last non-option flag in the list" do + GrepFu::Options.new(%w{offer}).search_criteria.should == 'offer' + GrepFu::Options.new(%w{a help --color}).search_criteria.should == 'help' + GrepFu::Options.new(%w{lib/tasks unrake --verbose --color}).search_criteria.should == 'unrake' + end + + it "should expand the file_path to one of the replacement variables, if found" do + GrepFu::Options.new(%w{a value}).file_path.should == 'app' + GrepFu::Options.new(%w{s hoozits}).file_path.should == 'spec' + GrepFu::Options.new(%w{mig down --color}).file_path.should == 'db/migrate' + end + + it "should accept an explicit find path, if provided" do + GrepFu::Options.new(%w{lib/tasks value}).file_path.should == 'lib/tasks' + end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 553f931..7ab6c90 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,6 +1,6 @@ def silence_warnings - old_verbose, $VERBOSE = $VERBOSE, nil - yield + old_verbose, $VERBOSE = $VERBOSE, nil + yield ensure - $VERBOSE = old_verbose + $VERBOSE = old_verbose end From 037f3ff3b0bf624a2b753134a23a3b93ef9caf58 Mon Sep 17 00:00:00 2001 From: Eric Budd Date: Wed, 16 Jun 2010 12:51:52 +0800 Subject: [PATCH 35/42] Made finder spec less brittle --- spec/find_builder_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/find_builder_spec.rb b/spec/find_builder_spec.rb index 40ac901..02f0527 100644 --- a/spec/find_builder_spec.rb +++ b/spec/find_builder_spec.rb @@ -49,7 +49,7 @@ end it "should stitch together a long, long find command" do - @find_command.should =~ /find path prune_list \\{ -size -100000c -type f \\} -print0 | xargs -0 grep str_opts \"crits\"/ + @find_command.should =~ /find path prune_list .. -size -100000c -type f .. -print0 | xargs -0 grep str_opts \"crits\"/ end end From 89b1bda9111d24e947bf6e8aef6083ec203a09a2 Mon Sep 17 00:00:00 2001 From: Eric Budd Date: Wed, 16 Jun 2010 12:52:39 +0800 Subject: [PATCH 36/42] Gentler exit when no arguments are provided --- lib/grep-fu.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/grep-fu.rb b/lib/grep-fu.rb index 6714b69..51fc80b 100644 --- a/lib/grep-fu.rb +++ b/lib/grep-fu.rb @@ -5,7 +5,7 @@ module GrepFu def self.run!(args = []) unless args.size > 0 puts Options.usage(__FILE__) - exit + return end options = Options.new(args) From 3bfcbb9eb9f806b830c95c9fca80b8cc464ab022 Mon Sep 17 00:00:00 2001 From: Eric Budd Date: Wed, 16 Jun 2010 12:53:02 +0800 Subject: [PATCH 37/42] Adding specs for runner logic --- spec/grep_fu_spec.rb | 76 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 spec/grep_fu_spec.rb diff --git a/spec/grep_fu_spec.rb b/spec/grep_fu_spec.rb new file mode 100644 index 0000000..cb7c6b8 --- /dev/null +++ b/spec/grep_fu_spec.rb @@ -0,0 +1,76 @@ +require 'grep-fu' +require 'spec/spec_helper' + +describe GrepFu do + describe "#run!" do + before(:each) do + GrepFu.stub!(:puts) + end + + describe "with no arguments provided" do + it "should print the usage and exit if no arguments are provided" do + GrepFu::Options.should_receive(:usage).and_return('Usage: etc.') + GrepFu.should_receive(:puts).with('Usage: etc.') + GrepFu.run! + end + + it "should exit early if no arguments are provided" do + GrepFu::Options.should_not_receive(:new) + GrepFu.run! + end + end + + describe "with valid arguments" do + before(:each) do + @options = mock(GrepFu::Options, :verbose => false, :single_line => false) + @find_command = "find me" + GrepFu::Options.stub!(:new).and_return(@options) + GrepFu::FindBuilder.stub!(:find_command).and_return(@find_command) + GrepFu.stub!(:'`') + end + + it "should create options from provided arguments" do + GrepFu::Options.should_receive(:new).with('arguments!') + GrepFu.run!('arguments!') + end + + it "should build a find command from options" do + GrepFu::FindBuilder.should_receive(:find_command).with(@options) + GrepFu.run!('arguments!') + end + + it "should display the results of the find" do + GrepFu.should_receive(:'`').with(@find_command) + GrepFu.run!(['stuff_to_find']) + end + + it "should appropriately format results for single-line requests" do + @options.stub!(:single_line).and_return(true) + GrepFu.stub!(:'`').and_return("line one\nline two\nlast line\n") + GrepFu.should_receive(:puts).with('line one line two last line') + GrepFu.run!(['--single-line']) + end + + it "should appropriately format results for verbose requests" do + @options.stub!(:verbose).and_return(true) + verbose_returns = [ + "app/views/mailer/new_notification.text.plain.erb:1:A new notification has arrived!", + "README:45: although it's not clear who might have", + "app/models/funge.rb:22: Hugenot.new" + ].join("\n") + + formatted_returns = [ + "app/views/mailer/new_notification.text.plain.erb:1:\n\tA new notification has arrived!", + "README:45:\n\talthough it's not clear who might have", + "app/models/funge.rb:22:\n\tHugenot.new" + ] + + GrepFu.stub!(:'`').and_return(verbose_returns) + GrepFu.should_receive(:puts).with(formatted_returns[0]) + GrepFu.should_receive(:puts).with(formatted_returns[1]) + GrepFu.should_receive(:puts).with(formatted_returns[2]) + GrepFu.run!(['not', '--verbose']) + end + end + end +end From de624c7ab75544747f59ac60ced8f55e60d35005 Mon Sep 17 00:00:00 2001 From: Eric Budd Date: Wed, 16 Jun 2010 13:10:06 +0800 Subject: [PATCH 38/42] Adding shebang line to bin file --- bin/grep-fu | 1 + 1 file changed, 1 insertion(+) diff --git a/bin/grep-fu b/bin/grep-fu index f31d697..5de0491 100755 --- a/bin/grep-fu +++ b/bin/grep-fu @@ -1,3 +1,4 @@ +#!/usr/bin/env ruby $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib') require 'grep-fu' From 34384e04655a8ce788d732c64bca4a669d3e6540 Mon Sep 17 00:00:00 2001 From: Eric Budd Date: Wed, 16 Jun 2010 13:11:23 +0800 Subject: [PATCH 39/42] Updated gemspec for 0.5.0 --- grep-fu.gemspec | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/grep-fu.gemspec b/grep-fu.gemspec index eb57a17..e8182a1 100644 --- a/grep-fu.gemspec +++ b/grep-fu.gemspec @@ -1,6 +1,4 @@ # Generated by jeweler -# re -# # DO NOT EDIT THIS FILE DIRECTLY # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command # -*- encoding: utf-8 -*- @@ -11,7 +9,7 @@ Gem::Specification.new do |s| s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= s.authors = ["Eric Budd"] - s.date = %q{2010-06-13} + s.date = %q{2010-06-16} s.default_executable = %q{grep-fu} s.description = %q{Grep-Fu is a very fast, Rails-oriented command-line helper script for grep.} s.email = %q{calamitous@calamitylane.com} @@ -29,13 +27,23 @@ Gem::Specification.new do |s| "grep-fu.gemspec", "lib/grep-fu.rb", "lib/grep-fu/find_builder.rb", - "lib/grep-fu/options.rb" + "lib/grep-fu/options.rb", + "spec/find_builder_spec.rb", + "spec/grep_fu_spec.rb", + "spec/options_spec.rb", + "spec/spec_helper.rb" ] s.homepage = %q{http://github.com/Calamitous/grep-fu} s.rdoc_options = ["--charset=UTF-8"] s.require_paths = ["lib"] s.rubygems_version = %q{1.3.6} s.summary = %q{Grep-Fu is a very fast, Rails-oriented command-line helper script for grep.} + s.test_files = [ + "spec/find_builder_spec.rb", + "spec/options_spec.rb", + "spec/spec_helper.rb", + "spec/grep_fu_spec.rb" + ] if s.respond_to? :specification_version then current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION From b46af89614cea87f648eb8e33f560ce679799841 Mon Sep 17 00:00:00 2001 From: Eric Budd Date: Wed, 16 Jun 2010 13:15:22 +0800 Subject: [PATCH 40/42] Regenerated gemspec for version 0.5.0 --- grep-fu.gemspec | 1 + 1 file changed, 1 insertion(+) diff --git a/grep-fu.gemspec b/grep-fu.gemspec index e8182a1..6b40be6 100644 --- a/grep-fu.gemspec +++ b/grep-fu.gemspec @@ -19,6 +19,7 @@ Gem::Specification.new do |s| "README.md" ] s.files = [ + ".gitignore", "LICENSE", "README.md", "Rakefile", From 78c76f1c20984ee3615b80ed6ec0c0d944a9b1c4 Mon Sep 17 00:00:00 2001 From: Joshua French Date: Thu, 16 Feb 2012 12:47:10 -0600 Subject: [PATCH 41/42] Prune docs from list, but add them as option --- lib/grep-fu/find_builder.rb | 3 ++- lib/grep-fu/options.rb | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/grep-fu/find_builder.rb b/lib/grep-fu/find_builder.rb index d73ae80..d92fe98 100644 --- a/lib/grep-fu/find_builder.rb +++ b/lib/grep-fu/find_builder.rb @@ -1,6 +1,7 @@ module GrepFu class FindBuilder - PRUNE_PATHS = ['/.svn', '/.git', '/vendor', '/log', '/public', '/tmp', '/coverage'] + PRUNE_PATHS = ['/.svn', '/.git', '/vendor', '/log', + '/public', '/tmp', '/coverage', '/doc'] def self.delicious_prunes "-path '*#{PRUNE_PATHS.join("' -prune -o -path '*")}' -prune -o" diff --git a/lib/grep-fu/options.rb b/lib/grep-fu/options.rb index c7e66ee..40bad07 100644 --- a/lib/grep-fu/options.rb +++ b/lib/grep-fu/options.rb @@ -5,6 +5,7 @@ class Options PATH_REPLACEMENTS = { 'a' => 'app', 'c' => 'app/controllers', + 'd' => 'doc', 'h' => 'app/helpers', 'm' => 'app/models', 'v' => 'app/views', From 30ee12976b6625a57be22bece2490cbfd738c42b Mon Sep 17 00:00:00 2001 From: Eric Budd Date: Sat, 13 Nov 2010 03:10:47 +0800 Subject: [PATCH 42/42] Added example to dox for --single-line feature --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index be0c2f3..fabeb14 100644 --- a/README.md +++ b/README.md @@ -117,6 +117,10 @@ 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 ---------------------