TextMate and iTerm2 v3

by 2/26/2016 09:18:00 AM 0 comments
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.

Brian Schlining

Developer

Cras justo odio, dapibus ac facilisis in, egestas eget quam. Curabitur blandit tempus porttitor. Vivamus sagittis lacus vel augue laoreet rutrum faucibus dolor auctor.

0 comments: