« Tomcat, Spring Web MVC, and Exceptions | Main | Odd addAsync() behavior when handling asynchronous events »

Patching iTerm

When I went searching for different terminal application for the Mac I found iTerm and have been very happy with it. It offers enough preferences to suit customization to my taste and it offers I couple of features I fell in love with from SecureCRT. In particular it offers a right-click open in browser option. I'm a luddite when it comes to working with email and prefer to use procmail, SpamAssassin, and Pine versus any of the various other email clients.

The problem with text only email is HTTP links that span multiple lines or get formatted with line breaks and spaces. Highlighting such a link and trying to launch it with the iTerm browser hook does nothing. I decided to "fix" this and as such created a small patch to iTerm Build 0.9.5.0611 that removes all white space from the highlighted text before handing it off to the browser. It seems to be working! Prior to this I've done no Objective-C programming so for all I know I've created a big memory leak. For anyone interested rough notes on what I did are below.

1. Getting the source
The latest CVS source doesn't build, so I pulled what seems to be the source for the last released version available for download

cvs -d:pserver:anonymous@iterm.cvs.sourceforge.net:/cvsroot/iterm login
cvs -z3 -d:pserver:anonymous@iterm.cvs.sourceforge.net:/cvsroot/iterm co -D "2007-07-01" -P iTerm

2. Patching PTYTextView.m
The _openURL method in PTYTextView.m handles launching the browser for the selected text. I modify the string prior to the protocol check. Since I'm still running on 10.4 I couldn't use some of the newer string manipulation methods.

3145c3145,3153
<
---
>
>     NSMutableString* tempString = [NSMutableString stringWithCapacity:[trimmedURLString length]];
>     [tempString setString:trimmedURLString];
>     [tempString replaceOccurrencesOfString:@" " withString:@"" options:NSLiteralSearch range:NSMakeRange(0, [tempString length])];
>     [tempString replaceOccurrencesOfString:@"\t" withString:@"" options:NSLiteralSearch range:NSMakeRange(0, [tempString length])];
>     [tempString replaceOccurrencesOfString:@"\n" withString:@"" options:NSLiteralSearch range:NSMakeRange(0, [tempString length])];
>     [tempString replaceOccurrencesOfString:@"\r" withString:@"" options:NSLiteralSearch range:NSMakeRange(0, [tempString length])];
>     trimmedURLString = tempString;
>

3. Compiling and Installing
From a terminal I ran make Deployment and then copied the resulting build/Deployment/iTerm.app over the existing version I had in my Application directory. The one change was that the preferences file name changed so I also ran:

cp ~/Library/Preferences/iTerm.plist ~/Library/Preferences/net.sourceforge.iTerm.plist

Tags: iterm mac

Comments

The NSMutableString that you create from the stringWithCapacity method should have already been added to the autorelease pool, so as long as the trimmedURLString is not being retained in the method you modified and iTerm isn't doing something funky with autorelease pools, I would think that you should not have any problems with memory leaks. Nice.
Cool! I stopped using iTerm around 0.85 because of this (and a few other glitches.