TextMate and iTerm2 v3

If you upgrade to the latest beta of iTerm (v3-ish), you will find that the iTerm support in TextMate is broken. i.e. Trying to launch an interactive shell from TextMate will fail. I wrote up a little bit of AppleScript to fix this issue.

Step 1

Open Script Editor and create a new doc. Paste the following code into it:

(* 

    Open Terminal Here 
     
    A toolbar script for Mac OS X 10.3/10.4
     
    Written by Brian Schlining
 *)


property debug : false

-- when the toolbar script icon is clicked 
-- 
on run argv
 set this_folder to item 1 of argv
 my process_item(this_folder)
end run



-- this subroutine processes does the actual work 
-- this version can handle this weirdo case: a folder named "te'st"ö te%s`t"

on process_item(this_item)
 
 set thePath to quoted form of POSIX path of this_item
 set theCmd to "cd " & thePath & ";clear;"
 
 tell application "iTerm"
  activate
  -- just open a terminal and cd to thePath
  --set newWindow to (create window with default profile)
  
  set aWindow to current window
  
  if aWindow is equal to missing value then
   set aWindow to (create window with default profile)
  else
   tell aWindow
    set t to (create tab with default profile)
   end tell
  end if
  
  
  tell current session of aWindow
   write text "cd " & thePath & ";clear;"
  end tell
  
 end tell
 
 
end process_item
Save the script somewhere as iTermLaunch.scpt.

Step 2

In TextMate, select "Bundles -> Edit Bundles" from the menu. Then select the "iTerm" bundle. Select Menu Actions in the iTerm bundle. Select "Interactive Shell" and edit the script like so (replace "/Path/to" with the real path to your iTermLaunch.scpt

#!/bin/bash
[[ -f "${TM_SUPPORT_PATH}/lib/bash_init.sh" ]] && . "${TM_SUPPORT_PATH}/lib/bash_init.sh"

# Start a new shell if needed, otherwise show the one with the right name.
#export SHELL_NAME=${SHELL_NAME:="TextMate Shell"}
#"$TM_BUNDLE_SUPPORT/new.sh"

osascript "/Path/to/iTermLaunch.scpt" ${TM_PROJECT_DIRECTORY}

Remember to save the bundle ([CMD]+S)

Step 3

There is no step 3. That's it. Just run that bundle item to open an iTerm shell in your current project.

iTerm2 version 3 Open iTerm Here Script

I just got a notice that iTerm2 has new major upcoming release (v. 3). I upgraded but found that the AppleScript dialect that iTerm used has changed. This change broke my handy little script that launches iTerm from a Finder window. So I took a few minutes to update it. The new code for iTerm2 v3 is below. Just copy and paste it into a new ScriptEditor window and save as iTermHere.scpt. You can then export it as an Application from ScriptEditor and drag it to your Finder toolbar. Here's the code:

(* 

    Open Terminal Here 
     
    A toolbar script for Mac OS X 10.3/10.4
     
    Written by Brian Schlining
 *)


property debug : false

-- when the toolbar script icon is clicked 
-- 
on run
 tell application "Finder"
  try
   set this_folder to (the target of the front window) as alias
  on error
   set this_folder to startup disk
  end try
  
  my process_item(this_folder)
  
 end tell
end run


-- This handler processes folders dropped onto the toolbar script icon 
-- 
on open these_items
 repeat with i from 1 to the count of these_items
  set this_item to item i of these_items
  my process_item(this_item)
 end repeat
end open


-- this subroutine processes does the actual work 
-- this version can handle this weirdo case: a folder named "te'st"ö te%s`t"

on process_item(this_item)
 
 set thePath to quoted form of POSIX path of this_item
 set theCmd to "cd " & thePath & ";clear;"
 
 tell application "iTerm"
  activate
  -- just open a terminal and cd to thePath
  --set newWindow to (create window with default profile)
  
  set aWindow to current window
  
  if aWindow is equal to missing value then
   set aWindow to (create window with default profile)
  else
   tell aWindow
    set t to (create tab with default profile)
   end tell
  end if
  
  
  tell current session of aWindow
   write text "cd " & thePath & ";clear;"
  end tell
  
 end tell
 
 
end process_item

Opening Sourcetree from TextMate

My goto editor these days is TextMate. (The recent 2.0 releases have been really great). Like many developers, I use git for source control. Most of the time I use git on the command line, but once in a while I'll open up a project in the very awesome, and very free SourceTree VCS Gui from Atlassian. To simplify opening a project in SourceTree when working from TextMate I added a command via TextMate's extremely simple and flexible Bundles. (Which, due to the simplicity and flexibility of bundle's in TextMate, just tromps on anything I've seen in any other text editor, sorry Sublime Text.).

First, you will need to install SourceTree. Once installed, launch it and select SourceTree > Install Command Line Tools to install the stree shell command.

To add the command to TextMate, do the following:

  1. In TextMate, go to Bundles > Edit Bundles
  2. Select the Bundle that you want to add your command to. I created one with my own name, but you can use existing ones.
  3. Hit [command]+N to open a dialog to Create a New Item
  4. In the Create New Item dialog choose Command
  5. In the sidebar, name it Open With SourceTree. Add your favorite key equivalent (I use [command]+. )
  6. Set Save to Nothing
  7. Set Input to Nothing
  8. Set Output to Discard
  9. In the script shell at the bottom enter the following:
    
    #!/usr/bin/env bash
    if [ -d $TM_DIRECTORY ] ; then
      cd $TM_DIRECTORY 
    elif [ -d $TM_PROJECT_DIRECTORY ] ; then
      cd $TM_PROJECT_DIRECTORY
    fi
      
    GIT_ROOT=$(git rev-parse --show-toplevel)
    if [ -d $GIT_ROOT ] ; then
      stree $GIT_ROOT
    fi
      
And that's it. Enjoy.

Strict Coding Style SBT project (using giter8)

At this moment ScalaDays is going on in nearby San Francisco. I came across a Toward a Safer Scala talk that emphasized writing safer Scala using strict static code analysis. After watching the talk I put together a giter8 template that implements their recommendations. If you have giter8 installed you can try out the basicscala template using:

g8 hohonuuli/basicscala.g8
Here's some things that this template provides:
  • Formats source files on compile using Scalariform
  • Adds strict scala compiler flags in build.sbt
  • Build fails on compiler warnings
  • Adds Wartremover to Scala's linter. You can run lint and wartremover in sbt using 'lint:compile'.
  • Includes junit and scalatest
  • Includes scala-style for checking code sytle. You will need to run 'sbt scalastyleGenerateConfig' to generate a scalastyle-config file. After which, you can run 'sbt scalastyle' to check your projects.