<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="/stylesheets/rss.css" type="text/css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>OnRails.org: TextMate filetype detection for script/runner Rails scripts</title>
    <link>http://onrails.org/articles/2007/04/20/textmate-filetype-detection-for-script-runner-rails-scripts</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>Ruby On Rails and related matters.</description>
    <item>
      <title>TextMate filetype detection for script/runner Rails scripts</title>
      <description>&lt;p&gt;So you&amp;#8217;re building some righteous automation for your killer web 2.0 app, placing scripts in &lt;code&gt;RAILS_ROOT/script&lt;/code&gt; that you can call from cron for nightly maintenance, etc.  To bootstrap your rails environment, you decide to use the shebang feature of script/runner, available since &lt;a href="http://dev.rubyonrails.org/changeset/5189"&gt;changeset 5189&lt;/a&gt;.  When you start to edit the script in TextMate (you &lt;strong&gt;are&lt;/strong&gt; using TextMate, aren&amp;#8217;t you?) there is no syntax highlighting to be found!  It&amp;#8217;s all plain text with no colors, and none of your ever-so-helpful keyboard macros work!  Frightful.  Well, take a deep breath, because together, we&amp;#8217;re going to get the filetype detection magic working for you.&lt;/p&gt;


	&lt;p&gt;Before we get started, it&amp;#8217;s helpful to know how filetype detection works.  TextMate does a couple of different types of filetype detection&amp;#8212;the first is based off of the extension, so if you named your script with a &lt;code&gt;.rb&lt;/code&gt; extension, you are probably wondering what in the world I&amp;#8217;m rambling about.  Dude.  It just works.&lt;/p&gt;


	&lt;p&gt;However, if you followed the rails convention for scripts, and did not use an extension with your filename, keep reading.  The second type of detection works by scanning the so called &amp;#8220;shebang&amp;#8221; line at the top of the script which tells the shell (and in this case TextMate) which interpreter to use to evaluate your script&amp;#8212;this is how we will tell TextMate that script/runner really means ruby.&lt;/p&gt;


	&lt;p&gt;First of all, you&amp;#8217;ll need to fire up the Bundle Editor and select &amp;#8220;Languages&amp;#8221; from the drop-down filter.  Expand the &amp;#8220;Rails&amp;#8221; node, and then select the &amp;#8220;Ruby on Rails&amp;#8221; language.  On the right side, you should see the definition being used by TextMate to detect the Ruby on Rails scope.  If you have not modified your bundle, you&amp;#8217;ll probably see that it is using a &lt;code&gt;fileTypes&lt;/code&gt; to look for &lt;code&gt;.rxml&lt;/code&gt; files.  This is where we want to insert the following line:&lt;/p&gt;


	&lt;p&gt;&lt;code&gt;    firstLineMatch = '^#!.*(script/runner)';&lt;/code&gt;&lt;/p&gt;


	&lt;p&gt;Here&amp;#8217;s a screenshot of what it should look like when you are done:
&lt;img src="http://onrails.org/files/BundleEditor-ROR.gif" alt="" /&gt;&lt;/p&gt;


	&lt;p&gt;Now go back to your script and enjoy all the colorized, scope-aware editing goodness that is TextMate!&lt;/p&gt;</description>
      <pubDate>Fri, 20 Apr 2007 14:54:00 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:5c2e6ed5-7d4d-469e-ba06-b9b34d68c913</guid>
      <author>Solomon White</author>
      <link>http://onrails.org/articles/2007/04/20/textmate-filetype-detection-for-script-runner-rails-scripts</link>
      <category>Rails Tips</category>
      <category>Ruby On Rails</category>
      <category>Rails</category>
      <category>script/runner</category>
      <category>textmate</category>
    </item>
  </channel>
</rss>
