Finding stuff in multiple files and opening them in gVIM

21 02 2010

Currently I'm working on some DokuWiki template which is based on the arctic template. DokuWiki itself scatters the CSS styles in several files like 'layout.css', 'design.css etc. The arctic template adds its own bunch of files like 'arctic_layout.css', 'arctic_design.css' and so on.

Now I needed to change the color of some page element. But where in this plethora of style files is the matching CSS definition? I called upon several good friends to find it.

Firstly I fired up FireBug which nicely showed which CSS classes were applied to that page element. As it turned out, the element was wrapped in a div tag and formatted by a CSS class named 'meta'.

Fine. Now I need to find the string "div.meta" (or, maybe just ".meta") in the style files. Of course we know the commands 'find' and 'grep' will quickly show us the results, but today -- as an additional sugar -- I wanted to open all found files together in the same instance of gVIM. Ah this is why I love the command line:

find . -name '*.css' -or -name '*.php' | xargs grep div.meta \
|awk -F: '{print $1;}' |sort -u | xargs gvim

Let's split that command up:

  1. The find command lets us only look into the wanted files. And it does that recursively, if we would need that.
  2. With xargs we feed those filenames nicely into grep. And grep prints each line which matches the expression, prepended with the name of the file where the line was found.
  3. We are only interested in the filenames, so awk will get them for us: "split the line at colons and print the first column".
  4. Maybe there are more than one matching lines in the same file. Therefore we build an unique list of 'em.
  5. And lastly, let xargs provide the list as arguments to gVIM

That's it.

Well, not quite. :-) DokuWiki allows to use some kind of variables in the CSS files. Consequently, the file which defines the CSS for 'div.meta' does not contain the sought color information, but the name of a variable. And this, FINALLY, I can change in the file 'style.ini'. Argh.


No Trackbacks


Display comments as (Linear | Threaded)
No comments

Add Comment

Standard emoticons like :-) and ;-) are converted to images.
E-Mail addresses will not be displayed and will only be used for E-Mail notifications.

To prevent automated Bots from commentspamming, please enter the string you see in the image below in the appropriate input box. Your comment will only be submitted if the strings match. Please ensure that your browser supports and accepts cookies, or your comment cannot be verified correctly.

Use the menu below to choose a header image. You can choose between images included with the theme or use a custom image.

If you are using both sidebars and you want to use an included image then choose one ending with "_large.jpg". For ex: red_sky_large.jpg instead of red_sky.jpg

To choose a custom image, select "custom header path" from the menu list and then click on the "media library" link. A custom header image must be 780x95 in size if you are using only one sidebar or 1000x95 if you are using both sidebars.

Please choose a header image: OUT ); define("FRESHY_CUSTOM_HEADER","Custom header path:"); define("FRESHY_HOMELINK_DESCRIPTION","Enter a custom label for the link pointing to your blog front page: "); define("FRESHY_NAVLINK_TITLE","Navigation link "); define("FRESHY_NAVLINK_DESCRIPTION_URL","Enter URL for Navigation link "); define("FRESHY_NAVLINK_ANCHOR_TEXT","Enter label for Navigation link "); define("FRESHY_NAVBG_TITLE","Navigation highlight colour"); define("FRESHY_NAVBG_DESCRIPTION","Please choose a navigation button highlight colour for this theme: "); define("FRESHY_NAVBG_GREEN","Green"); define("FRESHY_NAVBG_RED","Red"); define("FRESHY_NAVBG_LIGHT_BLUE","Light Blue"); define("FRESHY_NAVBG_BLUE","Blue"); define("FRESHY_NAVBG_PURPLE","Purple"); define("FRESHY_NAVBG_GRAY","Gray"); define("FRESHY_NAVBG_ORANGE","Orange"); define("FRESHY_NAVLINK_HOME","Home"); //only used for s9y versions <1.1 ?>