grep-fu 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (7) hide show
  1. data/LICENSE +20 -0
  2. data/README.rdoc +106 -0
  3. data/Rakefile +51 -0
  4. data/VERSION +1 -0
  5. data/bin/grep-fu +61 -0
  6. data/grep-fu.gemspec +45 -0
  7. metadata +68 -0
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Eric Budd
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,106 @@
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.
data/Rakefile ADDED
@@ -0,0 +1,51 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "grep-fu"
8
+ gem.summary = %Q{Grep-Fu is a very fast, Rails-oriented command-line helper script for grep.}
9
+ gem.description = %Q{Grep-Fu is a very fast, Rails-oriented command-line helper script for grep.}
10
+ gem.email = "calamitous@calamitylane.com"
11
+ gem.homepage = "http://github.com/Calamitous/grep-fu"
12
+ gem.authors = ["Eric Budd"]
13
+ end
14
+ Jeweler::GemcutterTasks.new
15
+ rescue LoadError
16
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
17
+ end
18
+
19
+ require 'rake/testtask'
20
+ Rake::TestTask.new(:test) do |test|
21
+ test.libs << 'lib' << 'test'
22
+ test.pattern = 'test/**/test_*.rb'
23
+ test.verbose = true
24
+ end
25
+
26
+ begin
27
+ require 'rcov/rcovtask'
28
+ Rcov::RcovTask.new do |test|
29
+ test.libs << 'test'
30
+ test.pattern = 'test/**/test_*.rb'
31
+ test.verbose = true
32
+ end
33
+ rescue LoadError
34
+ task :rcov do
35
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
36
+ end
37
+ end
38
+
39
+ task :test => :check_dependencies
40
+
41
+ task :default => :test
42
+
43
+ require 'rake/rdoctask'
44
+ Rake::RDocTask.new do |rdoc|
45
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
46
+
47
+ rdoc.rdoc_dir = 'rdoc'
48
+ rdoc.title = "grep-fu #{version}"
49
+ rdoc.rdoc_files.include('README*')
50
+ rdoc.rdoc_files.include('lib/**/*.rb')
51
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.3.0
data/bin/grep-fu ADDED
@@ -0,0 +1,61 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ PATH_REPLACEMENTS = {
4
+ 'a' => 'app',
5
+ 'c' => 'app/controllers',
6
+ 'h' => 'app/helpers',
7
+ 'm' => 'app/models',
8
+ 'v' => 'app/views',
9
+ 'l' => 'lib',
10
+ 'p' => 'public',
11
+ 'css' => 'public/stylesheets',
12
+ 'js' => 'public/javascripts',
13
+ 't' => 'test',
14
+ 's' => 'spec',
15
+ 'vp' => 'vendor/plugins',
16
+ 'mig' => 'db/migrate'
17
+ }
18
+
19
+ PRUNE_PATHS = ['/.svn', '/.git', '/vendor', '/log', '/public/yui', '/tmp', '~', '/coverage']
20
+ COLOR_ON_BY_DEFAULT = false
21
+ options = '-ril'
22
+
23
+ unless ARGV.size > 0
24
+ puts "\nUsage: #{__FILE__} [findpath] search_string [--verbose|--single-line]\n
25
+ Where findpath is one of the following:
26
+ any literal subdirectory
27
+ #{PATH_REPLACEMENTS.map { |abbr, txt| " #{abbr} - #{txt}" }.join("\n")}\n\n"
28
+ exit
29
+ end
30
+
31
+ clargs = ARGV
32
+
33
+ verbose = (clargs -= ['--verbose'] if clargs.include?('--verbose'))
34
+ single_line = (clargs -= ['--single-line'] if clargs.include?('--single-line'))
35
+ color = (clargs -= ['--color'] if (clargs.include?('--color')) || COLOR_ON_BY_DEFAULT)
36
+
37
+ if clargs.include?('--no-color')
38
+ clargs -= ['--no-color']
39
+ color = false
40
+ end
41
+
42
+ options = '-rin' if verbose
43
+ options << ' --color=always' if color
44
+
45
+ search_criteria = clargs.last
46
+ file_path = clargs.size == 2 ? PATH_REPLACEMENTS[clargs.first] || clargs.first : './'
47
+ delicious_prunes = PRUNE_PATHS ? "-path '*#{PRUNE_PATHS.join("' -prune -o -path *'")}' -prune -o" : ''
48
+
49
+ find_command = "find #{file_path} #{delicious_prunes} \\( -size -100000c -type f \\) -print0 | xargs -0 grep #{options} \"#{search_criteria}\""
50
+
51
+ if verbose
52
+ `#{find_command}`.each_line do |found|
53
+ file_and_line = found.slice!(/^.*?:.*?:/)
54
+ puts "#{file_and_line}\n\t#{found.strip}"
55
+ end
56
+ elsif single_line
57
+ puts `#{find_command}`.map { |found| found.chomp }.join(' ')
58
+ else
59
+ puts `#{find_command}`
60
+ end
61
+
data/grep-fu.gemspec ADDED
@@ -0,0 +1,45 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{grep-fu}
8
+ s.version = "0.3.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Eric Budd"]
12
+ s.date = %q{2010-05-12}
13
+ s.default_executable = %q{grep-fu}
14
+ s.description = %q{Grep-Fu is a very fast, Rails-oriented command-line helper script for grep.}
15
+ s.email = %q{calamitous@calamitylane.com}
16
+ s.executables = ["grep-fu"]
17
+ s.extra_rdoc_files = [
18
+ "LICENSE",
19
+ "README.rdoc"
20
+ ]
21
+ s.files = [
22
+ "LICENSE",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "bin/grep-fu",
27
+ "grep-fu.gemspec"
28
+ ]
29
+ s.homepage = %q{http://github.com/Calamitous/grep-fu}
30
+ s.rdoc_options = ["--charset=UTF-8"]
31
+ s.require_paths = ["lib"]
32
+ s.rubygems_version = %q{1.3.6}
33
+ s.summary = %q{Grep-Fu is a very fast, Rails-oriented command-line helper script for grep.}
34
+
35
+ if s.respond_to? :specification_version then
36
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
37
+ s.specification_version = 3
38
+
39
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
40
+ else
41
+ end
42
+ else
43
+ end
44
+ end
45
+
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: grep-fu
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 3
8
+ - 0
9
+ version: 0.3.0
10
+ platform: ruby
11
+ authors:
12
+ - Eric Budd
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-05-12 00:00:00 -05:00
18
+ default_executable: grep-fu
19
+ dependencies: []
20
+
21
+ description: Grep-Fu is a very fast, Rails-oriented command-line helper script for grep.
22
+ email: calamitous@calamitylane.com
23
+ executables:
24
+ - grep-fu
25
+ extensions: []
26
+
27
+ extra_rdoc_files:
28
+ - LICENSE
29
+ - README.rdoc
30
+ files:
31
+ - LICENSE
32
+ - README.rdoc
33
+ - Rakefile
34
+ - VERSION
35
+ - bin/grep-fu
36
+ - grep-fu.gemspec
37
+ has_rdoc: true
38
+ homepage: http://github.com/Calamitous/grep-fu
39
+ licenses: []
40
+
41
+ post_install_message:
42
+ rdoc_options:
43
+ - --charset=UTF-8
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ segments:
51
+ - 0
52
+ version: "0"
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ segments:
58
+ - 0
59
+ version: "0"
60
+ requirements: []
61
+
62
+ rubyforge_project:
63
+ rubygems_version: 1.3.6
64
+ signing_key:
65
+ specification_version: 3
66
+ summary: Grep-Fu is a very fast, Rails-oriented command-line helper script for grep.
67
+ test_files: []
68
+