##Setup Textmate for Rails Dev on OS X
##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.
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
- 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 beTM_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
- Find where rvm-auto-ruby is installed by executing the following in Terminal
- 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
andrvm use 1.9.2
respectively
- A Ruby file called
ruby_version.rb
with the following contentsputs RUBY_DESCRIPTION
- Open two tabs in Terminal and navigate to the root of each project.
cd ~/Sites/ruby187
andcd ~/Sites/ruby192
respectively
- 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
oropen 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 typingmate
in Terminal and hitting enter launches Textmate then all is well. If that doesn't work, check the following menuHelp > 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 clickCreate Link
. For most people who created that link when first installing Textmate this won't be an issue.
- Open each project's
ruby_version.rb
file by clicking on it from the project drawer in Textmate. Executecmd + 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]
- Enjoy your auto loaded Ruby!
##Essential Textmate Plugins/Bundles
- Github CSS Theme for more accurate Markdown previews
- RailsCasts Textmate Theme - Double Click the
RailsCasts.tmTheme
to install - Project+
- Minim Git Badges to go along with Project Plus. To install, simply drag the unzipped folder to:
Username > Library > Application Support > TextMate > Plugins > ProjectPlus.tmplugin > Contents > Resources > icons
- Explore the other settings in Project+ to tailor your install
##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.