views:

80

answers:

3

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?

+1  A: 

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.

altCognito
Good answer, I use firebug too but I want to be able to search for more than CSS bits, things like 'class="category-grid-products"'. I have tried grep via putty now, and it works a charm.
jsims281
+2  A: 

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.

smokris
Thanks! I didn't need to install cygwin as I have access to my server, but the grep examples were just what I needed.
jsims281
+4  A: 

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).

yhager
Woah, ack is /awesome/. Thanks for the link.
smokris