Tutorial :How can I search the contents of .module files?



Question:

I'm working with Drupal at the moment and I'm having a real hard time searching the contents of various .module files. For example I want to search for something like "div style="border: 1px solid red;" and find out which file it's in.

All my code editors ignore the .module files in their search because it is a strange extension. Windows won't do it because it's on a networked location.

Any ideas?


Solution:1

Install Cygwin, open a shell in your Drupal site's directory, and use grep --- a commandline utility to search files using regular expressions.

Something like this:

grep -r 'div style="border: 1px solid red;"' *  

would recursively search every file for that string.

Or:

find . -name '*.module' -exec grep -H 'div style="border: 1px solid red;"' {} \;  

would search only the .module files.


Solution:2

ack can do that for you pretty happily. For more convenience, you can also add in your .ackrc file the following: --type-set=drupal=.php,.inc,.module,.install,.info,.engine --type=drupal

So that typing

$ ack string  

will find string in all drupal files under the current directory.

(Yes, it runs on windows, see the link).


Solution:3

What I do:

Use firebug, it will tell you the exact file and then you can browse the system for that style. You'll want to turn off CSS caching for this temporarily.

Generally, there aren't too many (or shouldn't be any) CSS rules being defined in the .module files anyway.

If all else fails, you can use something like Agent Ransack or, for a more command line unixy feel, the king of command line search: grep.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »