Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Setup Textmate for Rails Dev on OS X

##Setup Textmate for Rails Dev on OS X

This guide was written by Jon Kinney for the Green Bay Ruby User Group. Jon works at Intridea and they graciously sponsor the Green Bay RUG meetings.

These guides were also partially completed using time from Intridea's SparkTime initiative which aims to give employees "outside projects" to work on during their normal work week.

If you find any issues with these suggestions please let me know. I've amassed these tips/tricks over several years of full time Rails development using Textmate but just because it works on my system doesn't always mean it will be problem free universally. Thanks to all the blog authors whose articles helped me learn Textmate over the years but whose links/posts I've lost or forgotten over time. If you have a cool Textmate tip or trick please post it in the comments!

##File/Folder Patterns

Wouldn't it be nice to be able to see hidden files and folders when working on a project in Textmate? As it turns out, it's built right in! Modify a few regex details with the tips below.

###Modify the File Pattern to allow viewing of specific hidden files

####Open Textmate's preferences and navigate to Folder References Textmate | Preferences | Advanced | Folder References

####Original File Pattern !(/.(?!htaccess)[^/]*|.(tmproj|o|pyc)|/Icon\r|/svn-commit(.[2-9])?.tmp)$

####The New File Pattern !(/.(?!htaccess|git*|rvm*)[^/]*|.(tmproj|o|pyc)|/Icon\r|/svn-commit(.[2-9])?.tmp)$

What's different from the default? |git*|rvm* was appended after !htaccess so that both .gitignore and .rvmrc files will appear in Textmate projects.

###Modify the Folder Pattern to allow viewing of hidden folders (except those specified)

####Original Folder Pattern !./(.[^/]|CVS|_darcs|_MTN|{arch}|blib|.~.nib|..(framework|app|pbproj|pbxproj|xcode(proj)?|bundle))$

####The New Folder Pattern !./(.git|.sass-cache|CVS|tmp|_darcs|_MTN|{arch}|blib|.~.nib|.*.(framework|app|pbproj|pbxproj|xcode(proj)?|bundle))$

What's different from the default? \.[^/]* was removed before |CSV and replaced with .git|.sass-cache. |tmp was also added after CSV. This will allow all hidden folders to be visible except for .git and .sass-cache. Other files/folders can easily be added following the patterns laid out above.

Auto Load multiple versions of Ruby on a per project basis through RVM

With RVM it's possible to have multiple Textmate projects open simultaneously each sand-boxed to it's own version of Ruby. This requires having .rvmrc files at the root of each project and using RVM's built in rvm-auto-ruby option. Textmate makes this trivial with it's ability to specify Shell Variables in it's preferences.

###Open Textmate's preferences and navigate to Shell Variables Textmate | Preferences | Advanced | Shell Variables

####Add a Variable

  1. Click the + button in the lower left corner to add a new Shell Variable. Notice a new line appears.
  • Double click on MY_VARIABLE and change it to be TM_RUBY
  • Double click on some value and change it to the appropriate path to rvm-auto-ruby
    • Find where rvm-auto-ruby is installed by executing the following in Terminal which rvm-auto-ruby
    • A typical location is something like: /Users/name/.rvm/bin/rvm-auto-ruby
  1. To test this setup make sure to install both Ruby 1.8.7 and Ruby 1.9.2 through RVM, then create two folders called ruby187 and ruby192 in ~/Sites. Each folder should include the following:
  • An .rvmrc file containing only
    • rvm use 1.8.7 and rvm use 1.9.2 respectively
  • A Ruby file called ruby_version.rb with the following contents puts RUBY_DESCRIPTION
  1. Open two tabs in Terminal and navigate to the root of each project.
  • cd ~/Sites/ruby187 and cd ~/Sites/ruby192 respectively
  1. Close out of Textmate entirely then issue the following command in Terminal at the root of each project to open it in Textmate mate .
  • In order for Textmate to load up the proper version of Ruby using rvm-auto-ruby all projects MUST be opened from Terminal using either mate or open project_name.tmproj (where "project_name" is the name that project's Textmate project file which you have to create and save manually). This is so that Textmate can read in the details of that project's .rvmrc file and dynamically set the Ruby version.
  • Note: Using the mate command assumes that Textmate's "Enhanced Terminal Usage" option is installed. If typing mate in Terminal and hitting enter launches Textmate then all is well. If that doesn't work, check the following menu Help > Terminal Usage.... * When editing the settings, pick /usr/bin or /usr/local/bin or any other directory that is ALWAYS in your path. Do not pick an RVM bin directory. Then click Create Link. For most people who created that link when first installing Textmate this won't be an issue.
  1. Open each project's ruby_version.rb file by clicking on it from the project drawer in Textmate. Execute cmd + r to run the current file in the context of that Textmate project. Depending on the patch-level and version currently installed with RVM...
  • In the ruby187 project something similar to the following should appear:
    ruby 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0]
  • In the ruby192 project something similar to the following should appear:
    ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-darwin10.7.0]
  1. Enjoy your auto loaded Ruby!

##Essential Textmate Plugins/Bundles

##ZSH/Bash Plugin

The use of ZSH through the oh-my-zsh project is becoming increasingly popular. Utilize the updated code snippet that I submitted to the RVM Textmate integration page under the "Miscellaneous" section and simply comment out the loading and unloading lines for your preferred shell. Thanks for merging in my changes Wayne!

This will allow the opening of a Textmate project from Terminal excluding several of the directories that make "find in project" slow. Couple this with the previous edits made to the Folder References section of the Textmate perferences and Textmate just got a lot more helpful!

Protip: After using the m . command that this code enables to open only the desired folders at the root of a given Rails project, save a Textmate project file (tmproj) which will store all the open tabs and open/closed folders just as they are when Textmate quits. This will allow for a much quicker return to coding when re-opening the project later.


This comment has been minimized.

Copy link

@Cerious Cerious commented Mar 18, 2014

the preferences window in my TextMate App does not have an advanced option what do i do

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment