Textmate: remove unnecessary files from Rails project

Posted by Jon
on Tuesday, November 13

Have you ever done a cmd-T or a global find in Textmate while working on a Rails project, and found more noise than signal in the results? For example, when trying to navigate to the routes.rb file, here is what I see:

routing.rb
routes.rb - config
routes.rb - configs
routes.rake
routing_test.rb
routing_error.html
routing_assertions.rb

This is because Textmate loads my entire vendor/ directory when I open up a project, including the entire Rails source. I can find the right file (it is routes.rb - config), but this breaks my focus and keeps searching and navigation from being transparent.

Similarly, log files are loaded into Textmate by default, which is terrible if you want to search across the entire site; I’ve had searches take 60 seconds or crash Textmate just because they were digging through enormous log files.

There is a simple way to fix this. Go to Preferences, and choose “Advanced” and then “Folder References”. You’ll see two regular expressions. They both start with a !, so any files that match the pattern will be excluded from Textmate. To stop searching through your vendored copy of Rails, just add this after the first parenthesis in the folder pattern:

vendor\/rails|

So the front of my folder pattern now looks like this:

!.*/(vendor\/rails|\.[^/]*

And to stop including log files, add this after the opening parenthesis in the file pattern:

.\.log|

The | is an “or” separator, so if you want to add more patterns, separate them by pipes. Pretty simple.

You can do quite a bit more, like excluding binary files (.jpg, .png, etc.), excluding plugins, etc. Just follow the same patterns as above.

Comments

Leave a response

  1. Tim ConnorNovember 13, 2007 @ 06:23 PM

    That’s pretty good for the default project state, but I find it’s worth it creating a custom project with a shallower heirarchy and an ogranization tuned to my usage, for frequently used projects. I add the contents of the apps folder right to the root of the project, and add the tests folders there too, and then throw the rest of the useful ones into an “others” group to keep them out of my way when I don’t need them. Add plugins instead of the whole vendor dir, etc.

  2. Barry HessNovember 13, 2007 @ 11:15 PM

    I do the same thing, Tim. It’s a very good solution to limit cruft in your work area.

  3. Chris KampmeierNovember 14, 2007 @ 12:22 AM

    @Tim: I’ve been using TextMate for years and I didn’t even know you could create “projects” beyond just opening an existing filesystem hierarchy. This is really helpful. Thanks.

  4. Nicholas HanceNovember 14, 2007 @ 07:47 AM

    This is good, but to go a step further, you can add these preferences on a per-project level. Which is helpful if, like myself, you need to work on projects in multiple languages.

    To do this, go to the root directory of your project and hit Command-I. From there, you can add the folder and file pattern on a per-project basis.

  5. Luke FranclNovember 14, 2007 @ 09:00 AM

    I use this technique to speed up jumping to a file and project searches. It works great…unless I want to look at the Rails source code. D’oh! I haven’t found any better solution than just opening up a new TextMate window with the vendor/rails directory.

    For faster searches in Rails projects, I’ve also installed the grep in project bundle. It’s much faster that TextMate’s own brain-dead search.

    On the command line, I’ve mostly switched to ack which is a Perl grep-alike with some enhancements to get around CVS/SVN turds and such automatically. It’s recursive by default.

  6. JonNovember 14, 2007 @ 12:08 PM

    @Tim, Nick, and Barry: I’m not that organized. :) In any given month, I’ll probably open up a dozen or so projects with TextMate, and I really like to just type “mate .” from the command line to open up whatever I need. So it is helpful for me to have a conventional organization across the board for every project.

    @Luke: I find the separation natural, since Rails and [My App] are two separate systems, and if I’m looking for something, I usually know where to look (and rarely want to search/navigate across BOTH my application and Rails).

    grep in project looks great – I hadn’t seen that before. I’ll give it a try.