<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>ColonelPanic &#187; screen</title>
	<atom:link href="http://colonelpanic.net/tag/screen/feed/" rel="self" type="application/rss+xml" />
	<link>http://colonelpanic.net</link>
	<description>Dumping our corps so you don&#039;t have to</description>
	<lastBuildDate>Mon, 30 Jan 2012 17:50:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Terminal Nirvana on Snow Leopard with SIMBL + Visor</title>
		<link>http://colonelpanic.net/2010/07/terminal-nirvana-on-snow-leopard-with-simbl-visor/</link>
		<comments>http://colonelpanic.net/2010/07/terminal-nirvana-on-snow-leopard-with-simbl-visor/#comments</comments>
		<pubDate>Wed, 21 Jul 2010 15:09:24 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[General Development]]></category>
		<category><![CDATA[Systems Administration]]></category>
		<category><![CDATA[end]]></category>
		<category><![CDATA[home]]></category>
		<category><![CDATA[screen]]></category>
		<category><![CDATA[simbl]]></category>
		<category><![CDATA[terminal]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[vim]]></category>
		<category><![CDATA[visor]]></category>

		<guid isPermaLink="false">http://colonelpanic.net/?p=255</guid>
		<description><![CDATA[Note 1: The method described here should also work in Mac OS X Leopard or Tiger, just get the appropriate versions of SIMBL / Visor. Note 2: If you don&#8217;t want everything on my bullet list, just follow the steps appropriate for what you want to accomplish. Note 3: I have provided .patch files, etc. [...]]]></description>
			<content:encoded><![CDATA[<blockquote><p><em><strong>Note 1</strong>: The method described here should also work in Mac OS X Leopard or Tiger, just get the appropriate versions of SIMBL / Visor.</em><br />
<em><strong>Note 2</strong>: If you don&#8217;t want everything on my bullet list, just follow the steps appropriate for what you want to accomplish.</em><br />
<em><strong>Note 3</strong>: I have provided .patch files, etc. at the bottom of the post for those who, like me, are a bit lazy.</em></p></blockquote>
<h2>What is Terminal Nirvana?</h2>
<p>As a developer, Terminal is one of my best friends. Maybe you can relate. I have constantly been in search of the ultimate Terminal configuration, and it has ever eluded me&#8230; until now.</p>
<p>But what is Terminal Nirvana? Here are my criteria:</p>
<ol>
<li><strong>I want the Home / End keys to move the cursor to the front / end of the line. </strong>I grew up on Windows, and I like the keys to function this way. To me, it just makes sense. Unfortunately, <a title="KeyFixer" href="http://www.starryhope.com/tech/apple/2006/keyfixer/">KeyFixer</a> doesn&#8217;t work in Terminal (but I highly recommend it for changing the behavior in most other apps!).</li>
<li><strong>I don&#8217;t want Home / End to behave differently when I am in a <a title="GNU Screen" href="http://en.wikipedia.org/wiki/Gnu_screen">screen</a> session.</strong> I use screen all the time, and Home / End need to behave consistently.</li>
<li><strong>I don&#8217;t want Home / End to do unexpected things in </strong><strong><a href="http://en.wikipedia.org/wiki/Vim_(text_editor)">VIM</a> &#8211; ever</strong><strong>.</strong> Pressing Home / End in VIM should, at the very least, not do weird things like delete lines, whether I am in a screen session or not.</li>
<li><strong>I want my terminal window available at all times.</strong> With as much as I use the terminal, opening Terminal.app all the time feels wasteful. There should be a better way. This is where <a title="SIMBL" href="http://www.culater.net/software/SIMBL/SIMBL.php">SIMBL</a> and <a title="Visor" href="http://visor.binaryage.com/">Visor</a> come in.</li>
<li><strong>I don&#8217;t want it to show up in the Dock, or in my Command + Tab list.</strong> As useful as Terminal is, there are a lot of other useful applications around, and I use a lot of them. Since I always want Terminal open anyway, it is annoying to constantly avoid / ignore / tab over it when I am using Command + Tab to switch to another running application. Oh, and it should stay away from my Dock, too.</li>
<li><strong>I want good, configurable colors in my shell.</strong> Fortunately, Visor takes care of this one by including <a title="Terminal Colors in Leopard / Snow Leopard" href="http://ciaranwal.sh/2007/11/01/customising-colours-in-leopard-terminal">TerminalColours</a> as part of the package, so you get this one &#8220;for free.&#8221;</li>
</ol>
<p>Sound like a tall order? It took me a few hours crawling around the web and experimenting to come up with a good solution, but I managed it in the end. Hopefully my experience can help save a few people some time in the future.</p>
<p>This is how I did it.<br />
<span id="more-255"></span></p>
<h2>First things first</h2>
<p>Before you go any further, make sure you have installed <a title="SIMBL" href="http://www.culater.net/software/SIMBL/SIMBL.php">SIMBL</a> and <a title="Visor" href="http://visor.binaryage.com/">Visor</a>. The latest versions work great in Snow Leopard with a 64-bit Terminal.app, so knock yourself out.</p>
<h2>Home / End keys</h2>
<p>To change the Home / End keys in Terminal.app, you are going to need to go to Terminal -&gt; Preferences -&gt; [Settings] -&gt; [Keyboard]. Remember, settings are profile-specific, so you will need to make the changes to any profiles you care about. (<em>Note: Visor uses the &#8220;Visor&#8221; profile, regardless of what you set as your default profile. What I do is rename the automatically-created &#8220;Visor&#8221; profile, configure my default profile, and then duplicate it with the name &#8220;Visor&#8221;.</em>)</p>
<p>The first thing I tried was changing the keybindings to &#8220;\001&#8243; and &#8220;\005&#8243; per the instructions I found on <a href="http://www.rickycampbell.com/fix-osx-terminal-pgup-pgdn-home-and-end/">Ricky Campbell&#8217;s blog</a>. This seemed to make sense; CTRL+A and CTRL+E move the cursor to the front / end of the line in Terminal. And I thought it was working perfectly, for a few glorious moments&#8230;</p>
<p>Unfortunately, CTRL+A is also the key combination to start a command in screen. So when I launched screen, suddenly my home key didn&#8217;t work anymore, and I randomly started sending screen commands when I used it.</p>
<p>I also tried using a ~/.inputrc file and the keybindings &#8220;\033[1~&#8221; and &#8220;\033[4~&#8221; as discussed on <a href="http://fplanque.com/dev/mac/mac-osx-terminal-page-up-down-home-end-of-line">two</a> <a href="http://linuxart.com/log/archives/2005/10/13/super-useful-inputrc/">blogs</a> I stumbled across while looking for an alternate solution. Now, I really thought I had the problem licked. Except, Home / End did weird things in VIM running within a screen session, and the necessity of using an additional .inputrc file was just a bit of a bummer.</p>
<p>Turns out Shift + Home and Shift + End  already did what I wanted, so the simplest solution of all is to just copy those keybindings already present in the Terminal settings. For good measure, I copied the &#8220;shift page up&#8221; and &#8220;shift page down&#8221; bindings to &#8220;page up&#8221; and &#8220;page down.&#8221; (<em>Note: you can either copy-paste the existing values, or hit ESC to get the \033 value and then type the other characters manually.</em>)</p>
<h3>Terminal key bindings:</h3>
<ul>
<li>home
<ul>
<li>Value: \033[H</li>
</ul>
</li>
<li>end
<ul>
<li>Value: \033[F</li>
</ul>
</li>
<li>page up
<ul>
<li>Value: \033[5~</li>
</ul>
</li>
<li>page down
<ul>
<li>Value: \033[6~</li>
</ul>
</li>
</ul>
<h2>Fixing VIM in screen</h2>
<p>Okay, almost there with the keybindings. If you run VIM inside a screen session, you will notice that Home deletes the current line, and using the arrow keys while in insert mode inserts A / B / C / D rather than moving the cursor. Not good.</p>
<p>A little tweak to your existing ~/.vimrc file will fix it right up (or, if you don&#8217;t have an existing ~/.vimrc, create it). (<em>Note: the easiest way to get the proper escape characters is to enter insert mode, and hit CTRL+V followed by the Home or End key. This will add the ^[ escape character, as well as the [F or [H characters. Do the same thing for CTRL + O to get the ^O escape character.</em>) By using CTRL+O on the imap lines, we make the Home / End keys work the same way in insert mode or command mode.</p>
<p>As an added bonus, this fixes the arrow keys while in insert mode. Though, to be honest, I have no idea why&#8230;</p>
<div class="wp_syntax">
<div class="code">
<pre class="vim" style="font-family:monospace;"><span style="color: #C5A22D;">&quot;&quot;</span><span style="color: #adadad; font-style: italic;">&quot; ~/.vimrc</span>
&nbsp;
<span style="color: #C5A22D;">&quot;&quot;</span><span style="color: #adadad; font-style: italic;">&quot; Fix home and end keybindings for screen</span>
<span style="color: #804040;">map</span> <span style="color: #000000;">^</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#91;</span>F <span style="color: #000000;">$</span>
imap <span style="color: #000000;">^</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#91;</span>F <span style="color: #000000;">^</span>O<span style="color: #000000;">$</span>
<span style="color: #804040;">map</span> <span style="color: #000000;">^</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#91;</span>H g0
imap <span style="color: #000000;">^</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#91;</span>H <span style="color: #000000;">^</span>Og0</pre>
</div>
</div>
<h2>Making Terminal always available</h2>
<p>This one was actually pretty simple. Using <a title="SIMBL" href="http://www.culater.net/software/SIMBL/SIMBL.php">SIMBL</a> and <a title="Visor" href="http://visor.binaryage.com/">Visor</a> (both compatible with 64-bit Terminal at the time of this writing) you can get Terminal to dock to the top / side / bottom of your screen, and configure it to open with a keystroke you can define.</p>
<p>My keystroke is Command + Esc (turn off Front Row first, if you hate it as much as I do). Once Terminal has been launched for the first time (thus creating the Visor window), this keystroke gets you in from anywhere, or hides it when you are done.</p>
<h2>Hiding the Dock icon, and removing Terminal from the Command + Tab list</h2>
<p>This is the most involved step, but it also provides one of the biggest benefits in my mind. Most of the information here comes from a <a href="http://www.metaskills.net/2009/8/18/visor-terminal-on-snow-leopard">MetaSkills blog article</a>.</p>
<p>In order to accomplish this, the LSUIElement key in Terminal&#8217;s Info.plist must be set to &#8220;1&#8243;. This disables the Dock icon and removes the application from the Command + Tab list. Don&#8217;t want to completely prevent Terminal from ever functioning like a normal application? The quick solution is to create new application &#8220;VisorTerminal.app&#8221; which is used for Visor, while leaving Terminal.app alone to function as normal. (This is actually a good thing, because another side-effect of setting LSUIElement : 1 is you no longer have anything change in the menubar when you are in your application&#8230; ie, you can&#8217;t click on VisorTerminal next to the Apple icon, and go into Preferences.)</p>
<h3>Create a new VisorTerminal.app</h3>
<p>Duplicate the existing Terminal.app.</p>
<div class="wp_syntax">
<div class="code">
<pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">cp</span> <span style="color: #660033;">-r</span> <span style="color: #000000; font-weight: bold;">/</span>Applications<span style="color: #000000; font-weight: bold;">/</span>Utilities<span style="color: #000000; font-weight: bold;">/</span>Terminal.app <span style="color: #000000; font-weight: bold;">/</span>Applications<span style="color: #000000; font-weight: bold;">/</span>Utilities<span style="color: #000000; font-weight: bold;">/</span>VisorTerminal.app</pre>
</div>
</div>
<p>Once you have duplicated Terminal.app, you need to change a few bundle identifiers in your new application so the two appear as distinct entities to Mac OS X. In other words, change &#8220;Terminal&#8221; to &#8220;VisorTerminal&#8221; in a few places. This is also when you add LSUIElements : 1.</p>
<div class="wp_syntax">
<div class="code">
<pre class="xml" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">&lt;!-- /Applications/Utilities/VisorTerminal.app/Contents/Info.plist --&gt;</span>
...
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>CFBundleDisplayName<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>VisorTerminal<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
...
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>CFBundleIdentifier<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>com.apple.VisorTerminal<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
...
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>CFBundleName<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>VisorTerminal<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
...
<span style="color: #808080; font-style: italic;">&lt;!-- Note: Put this right before the closing &lt;/dict&gt;&lt;/plist&gt;</span>
<span style="color: #808080; font-style: italic;">     at the end of the file --&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>LSUIElement<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
...</pre>
</div>
</div>
<p>At this point, rather than entering my preferences all over again, I elected to copy my Terminal.app preferences. Repeat this step any time you make preference changes that you want to copy over. (<em>Note: using a symlink does not seem to work. If you make changes while in VisorTerminal, such as changing the Visor hotkey, the modified file is saved over your symlink.</em>)</p>
<div class="wp_syntax">
<div class="code">
<pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">cp</span> ~<span style="color: #000000; font-weight: bold;">/</span>Library<span style="color: #000000; font-weight: bold;">/</span>Preferences<span style="color: #000000; font-weight: bold;">/</span>com.apple.Terminal.plist ~<span style="color: #000000; font-weight: bold;">/</span>Library<span style="color: #000000; font-weight: bold;">/</span>Preferences<span style="color: #000000; font-weight: bold;">/</span>com.apple.VisorTerminal.plist</pre>
</div>
</div>
<h3>Modify Visor to use VisorTerminal.app</h3>
<p>Once your new application is created and ready to go, you need to tell Visor to activate for that application rather than Terminal.app. Apply the following very familiar tweaks to Visor&#8217;s Info.plist:</p>
<div class="wp_syntax">
<div class="code">
<pre class="xml" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">&lt;!-- ~/Library/Application\ Support/SIMBL/Plugins/Visor.bundle/Contents/Info.plist --&gt;</span>
...
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>BundleIdentifier<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>com.apple.VisorTerminal<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
...
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>ExecPattern<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>*/VisorTerminal.app/Contents/MacOS/Terminal<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
...
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>BundleIdentifier<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>com.apple.VisorTerminal<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
...</pre>
</div>
</div>
<p>Once this last step is done, you are almost there. Make sure Terminal.app and VisorTerminal.app are both closed. Now, launch VisorTerminal.app and behold its wonder!</p>
<div class="wp_syntax">
<div class="code">
<pre class="bash" style="font-family:monospace;">open <span style="color: #000000; font-weight: bold;">/</span>Applications<span style="color: #000000; font-weight: bold;">/</span>Utilities<span style="color: #000000; font-weight: bold;">/</span>VisorTerminal.app</pre>
</div>
</div>
<h2>What? It didn&#8217;t work?</h2>
<p>Let me guess. A Terminal window opened, but Visor didn&#8217;t take effect. What gives? (You may have also noticed that you don&#8217;t have an entry in your menubar&#8230; see above.)</p>
<p>Turns out newer versions of SIMBL <a href="http://code.google.com/p/simbl/issues/detail?id=9">don&#8217;t activate in applications with LSUIElement : 1</a>. Apparently this is expected behavior due to the Cocoa event mechanism. But all is not lost!</p>
<p>You can manually inject SIMBL into an application using Apple Script.</p>
<div class="wp_syntax">
<div class="code">
<pre class="applescript" style="font-family:monospace;"><span style="color: #ff0033; font-weight: bold;">tell</span> <span style="color: #0066ff;">application</span> <span style="color: #009900;">&quot;VisorTerminal&quot;</span>
	inject SIMBL <span style="color: #0066ff;">into</span> Snow Leopard
<span style="color: #ff0033; font-weight: bold;">end</span> <span style="color: #ff0033; font-weight: bold;">tell</span></pre>
</div>
</div>
<p>Great, but I don&#8217;t want to do something manually every time I want a Visor window. I just want it to always be there, remember?</p>
<p>Use the <a href="http://www.tuaw.com/2007/12/27/applescript-the-script-editor/">AppleScript Editor</a> to save this snippet as an application, and then include that application in your user startup items. Voila! When you log in, the AppleScript helper executes, which launches VisorTerminal with SIMBL injected. Visor activates, your terminal automatically hides itself, yet is always there when you want it with the push of a button. It doesn&#8217;t clutter up your Dock, your application switching, and you can still use Terminal.app as usual whenever it makes sense to do so.</p>
<h2>Final thoughts</h2>
<p>First off, note that this tutorial was written using <em>SIMBL 0.9.7a</em>, <em>Visor 2.2</em>, and <em>Terminal 2.1.1 (273)</em> on Mac OS X <em>Snow Leopard 10.6.4</em>. YMMV.</p>
<p>Secondly, my thanks to all the people who are smarter than me and figured all this out. All I did was put things together.</p>
<p>Third, see below for patch files and my AppleScript application.</p>
<p>Finally, does anyone have the following issue, and know a way around it? After setting my key bindings, when I launch Terminal for the first time, they don&#8217;t take effect. Home does nothing special. If I open a new Terminal window, the home key starts working as expected, both in the new window as well as the original window. This happens to me whether I use \001 for the control character (and this without a ~/.inputrc file) or if I use the solution described above. Slightly bothersome, but since I almost always use my Visor terminal (which doesn&#8217;t exhibit the same problem&#8230; nor did it using Visor sans any modifications discussed here) I don&#8217;t notice it too often.</p>
<p><strong>Patch files:</strong> <a href="http://gist.github.com/484082">http://gist.github.com/484082</a><br />
<strong>AppleScript app:</strong> <a href="http://colonelpanic.net/wp-content/uploads/2010/07/HiddenVisorTerminal.zip">HiddenVisorTerminal.zip</a></p>
]]></content:encoded>
			<wfw:commentRss>http://colonelpanic.net/2010/07/terminal-nirvana-on-snow-leopard-with-simbl-visor/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

