PageRenderTime 97ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/README.md

https://github.com/Calamitous/grep-fu
Markdown | 188 lines | 111 code | 77 blank | 0 comment | 0 complexity | 2e08449fdafe4a7f2070c21ecd45d458 MD5 | raw file
  1. NOTE:
  2. =====
  3. This project is left here for historical purposes, but it has been eclipsed by other grep replacements like [ack](https://beyondgrep.com/), [silver searcher](https://github.com/ggreer/the_silver_searcher), and [ripgrep](https://github.com/BurntSushi/ripgrep) (personally, I'm using ripgrep these days).
  4. Thank you to everyone who contributed to and benefited from grep-fu.
  5. Grep-Fu
  6. =======
  7. 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:
  8. grep-fu account_deletion
  9. This will display a list of files which contain the search text:
  10. ./app/models/account.rb
  11. ./app/controllers/accounts_controller.rb
  12. *NOTE:* Grep-Fu will only work as expected if you are in the root directory of a Rails project!
  13. Installation
  14. ------------
  15. Grep-Fu is now a gem:
  16. gem install grep-fu
  17. Often, it can help reduce typing by aliasing the admittedly lengthy "grep-fu" command:
  18. alias g='grep-fu'
  19. Putting this (or a similar shortcut) in your .bashrc or .profile will allow you to use a shorthand version of the command:
  20. g account_deletion
  21. Even Faster
  22. -----------
  23. For more targeted (faster) searches, you can specify one of the following flags to narrow down the search:
  24. a - app
  25. m - app/models
  26. c - app/controllers
  27. v - app/views
  28. h - app/helpers
  29. l - lib
  30. p - public
  31. css - public/stylesheets
  32. js - public/javascripts
  33. s - spec
  34. t - test
  35. vp - vendor/plugins
  36. mig - db/migrate
  37. So to search only your helpers for the term "helpless":
  38. grep-fu h helpless
  39. Multiple word searches and searches containing special regex characters should be surrounded by quotes:
  40. grep-fu s "should be tested"
  41. grep-fu "^[^\?] fishy fishy fishy fish$"
  42. Running grep-fu without parameters will show you what options are available.
  43. Off the Beaten Path
  44. ----------------------------
  45. 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:
  46. grep-fu lib/tasks troweler
  47. You can even step up out of the current directory. Grep-Fu will use any path shortcuts your underlying OS recognizes.
  48. grep-fu ../../different_rails_project "def similar_method"
  49. grep-fu ~/Projects/roger_tracking last_known_location
  50. I want to see what it found!
  51. ----------------------------
  52. For more detail, you can add the '--verbose' flag to command:
  53. grep-fu c budget_dragon --verbose
  54. This will output the filename, line number, and found line.
  55. ./app/model/budget.rb:18:
  56. budget_dragon # Bob in accounting's been drinking again
  57. This should be used for fairly narrow searches, as it can produce a whole lot of output.
  58. Thanks go out to [Scotty Moon](http://github.com/scottymoon) for this feature.
  59. Colors
  60. ------
  61. If you'd like to see grep-fu's output in color, add the '--color' flag:
  62. grep-fu mig ExtraBiggened --color --verbose
  63. Under most color schemes, the --color option is only useful if --verbose is used as well.
  64. 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:
  65. grep-fu mig DoublePlusUnBiggened --no-color
  66. Thanks go out to [Joshua French](http://github.com/osake) for this feature.
  67. Single-Line Output
  68. ------------------
  69. Sometimes you need to output all the files grep-fu finds onto a single line; for example, when piping the list into another command:
  70. grep-fu "# Pipe me!" --single-line
  71. The list of files with matches will display on a single line:
  72. ./test/unit/calamity_test.rb ./test/unit/havoc_test.rb ./test/unit/mayhem_test.rb...
  73. This is handy if you want to go ahead and load all the files it finds into a text editor.
  74. gvim -p `gx "#TODO"`
  75. Ignoring More Stuff
  76. ---------------------
  77. 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.
  78. For example, if you have an unusually large set of migrations, you might want to step over them by default. Change the line
  79. PRUNE_PATHS = ['/.svn', '/.git', '/vendor', '/log', '/public', '/tmp', '/coverage']
  80. to
  81. PRUNE_PATHS = ['/.svn', '/.git', '/vendor', '/log', '/public', '/tmp', '/coverage', '/db/migrations']
  82. And migrations will no longer be searched. Note that targeted searches and specified directories always override the PRUNE_PATHS option.
  83. Version Information
  84. -------------------
  85. Passing the '--version' flag to grep-fu will return the current version.
  86. grep-fu --version
  87. returns
  88. grep-fu 0.5.0
  89. Technical mumbo-jumbo
  90. ---------------------
  91. 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:
  92. * public
  93. * logs
  94. * vendor
  95. * tmp
  96. * coverage
  97. * .svn
  98. * .git
  99. Note that all these directories are still searchable with targeted searches or a directory specification; they're simply not searched by default
  100. Grep-fu also ignores files larger than 100K, which tend to be unsearchable binaries or SQL dumps.
  101. 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.
  102. Note on Patches/Pull Requests
  103. -----------------------------
  104. * Fork the project.
  105. * Make your feature addition or bug fix.
  106. * Commit, do not mess with rakefile, version, or history.
  107. (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)
  108. * Send me a pull request. Bonus points for topic branches.
  109. Copyright
  110. ---------
  111. Copyright (c) 2010 Eric Budd. See LICENSE for details.