<?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; Ben</title>
	<atom:link href="http://colonelpanic.net/author/ben/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</generator>
		<item>
		<title>iOS and iCloud: overcoming &#8220;bad file descriptor&#8221; errors</title>
		<link>http://colonelpanic.net/2012/01/ios-and-icloud-overcoming-bad-file-descriptor-errors/</link>
		<comments>http://colonelpanic.net/2012/01/ios-and-icloud-overcoming-bad-file-descriptor-errors/#comments</comments>
		<pubDate>Tue, 17 Jan 2012 06:49:48 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[General Development]]></category>
		<category><![CDATA[icloud]]></category>
		<category><![CDATA[ios]]></category>
		<category><![CDATA[objective-c]]></category>

		<guid isPermaLink="false">http://colonelpanic.net/?p=638</guid>
		<description><![CDATA[Pretty quick one today. I beat my head against this for several hours before I found the obvious solution, so I thought I&#8217;d jot the info down here for reference, and maybe to help someone else out. NOTE: There is now a relevant answer on StackOverflow. Unfortunately, this answer wasn&#8217;t there when I needed it. [...]]]></description>
			<content:encoded><![CDATA[<p>Pretty quick one today. I beat my head against this for several hours before I found the obvious solution, so I thought I&#8217;d jot the info down here for reference, and maybe to help someone else out.</p>
<p><strong>NOTE:</strong> There is now <a href="http://stackoverflow.com/questions/8714525/cannot-sync-simple-text-file-with-icloud-bad-file-descriptor">a relevant answer</a> on StackOverflow. Unfortunately, this answer wasn&#8217;t there when I needed it.</p>
<h3>The problem</h3>
<p>Recently, while adding <a href="http://www.apple.com/icloud/">iCloud</a> support to the <a title="Day One - your premier journaling solution." href="http://dayoneapp.com/">Day One</a> iOS app, I ran into an issue copying files to and from the application&#8217;s Documents directory and its corresponding iCloud directory. Day One can run in one of three modes:</p>
<ol>
<li>Sync entries via iCloud</li>
<li>Sync entries via <a href="https://www.dropbox.com/">Dropbox</a></li>
<li>Don&#8217;t sync entries</li>
</ol>
<p>If you&#8217;ve developed for iCloud at all, you know that iCloud documents live within specific, &#8220;ubiquitous&#8221; directories on the user&#8217;s device (discovered via NSFileManager&#8217;s URLForUbiquityContainerIdentifier: method). So in order to enable iCloud sync, we needed to copy all files into the appropriate ubiquitous container. Conversely, if the user elects to disable iCloud then we need to copy all files from the ubiquitous container into the application&#8217;s Documents directory.</p>
<h3>The assumption</h3>
<p>We wrote a simple method to copy files from one directory to another, either going into or coming out of iCloud. It uses a basic NSDirectoryEnumerator to find all the files in the current source directory, check if they are present in the destination directory, and copy them there if they aren&#8217;t. Here&#8217;s a simplified example:</p>
<div class="wp_syntax">
<div class="code">
<pre class="objc" style="font-family:monospace;"><span style="color: #400080;">NSURL</span> <span style="color: #002200;">*</span>sourceDir <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>self currentWorkingDir<span style="color: #002200;">&#93;</span>; <span style="color: #11740a; font-style: italic;">// current directory, ie ubiquitous iCloud directory</span>
<span style="color: #400080;">NSURL</span> <span style="color: #002200;">*</span>destDir <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>self destDirForMovingFromDir<span style="color: #002200;">:</span>sourceDir<span style="color: #002200;">&#93;</span>; <span style="color: #11740a; font-style: italic;">// where should we copy to?</span>
<span style="color: #400080;">NSFileManager</span> <span style="color: #002200;">*</span>fm <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSFileManager</span> defaultManager<span style="color: #002200;">&#93;</span>;
<span style="color: #400080;">NSDirectoryEnumerator</span> <span style="color: #002200;">*</span>dirEnum <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>fm enumeratorAtPath<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span>sourceDir path<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
&nbsp;
<span style="color: #400080;">NSError</span> <span style="color: #002200;">*</span>mergeError;
<span style="color: #a61390;">while</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">&#40;</span>sourceFile <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>dirEnum nextObject<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
    <span style="color: #400080;">NSURL</span> <span style="color: #002200;">*</span>sourceFileURL <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>sourceDir URLByAppendingPathComponent<span style="color: #002200;">:</span>sourceFile<span style="color: #002200;">&#93;</span>;
    <span style="color: #400080;">NSURL</span> <span style="color: #002200;">*</span>destFileURL <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>destDir URLByAppendingPathComponent<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span>sourceFile lastPathComponent<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>;
    <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">!</span><span style="color: #002200;">&#91;</span>fm fileExistsAtPath<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span>destFileURL path<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
        <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">!</span><span style="color: #002200;">&#91;</span>fm copyItemAtURL<span style="color: #002200;">:</span>sourceFileURL toURL<span style="color: #002200;">:</span>destFileURL error<span style="color: #002200;">:&amp;</span>mergeError<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
            NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;ERROR (copy error): %@ -&gt; %@ - %@&quot;</span>, sourceFileURL, destFileURL, mergeError<span style="color: #002200;">&#41;</span>;
        <span style="color: #002200;">&#125;</span>
    <span style="color: #002200;">&#125;</span>
<span style="color: #002200;">&#125;</span></pre>
</div>
</div>
<p>I frequently found &#8220;bad file descriptor&#8221; errors being logged out. We were assuming that the NSDirectoryEnumerator would only list files that were actually present on the device. As it turns out, that is not the case when enumerating a ubiquitous directory.</p>
<h3>The solution</h3>
<p>Once you realize that the NSDirectoryEnumerator will list all ubiquitous files that exist on any device, regardless of whether or not they have been downloaded to the current device, the solution becomes pretty obvious:</p>
<p><em>You can&#8217;t copy a file that hasn&#8217;t been downloaded.</em></p>
<p>Adding that check is fairly straight forward. Since our method doesn&#8217;t know if we are going into or out of iCloud, we implemented a pretty general solution. Modifying the above example, it looks something like this:</p>
<div class="wp_syntax">
<div class="code">
<pre class="objc" style="font-family:monospace;">...
<span style="color: #a61390;">while</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">&#40;</span>sourceFile <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>dirEnum nextObject<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
    ...
    <span style="color: #11740a; font-style: italic;">// By default, assume all files are able to be copied.</span>
    <span style="color: #400080;">NSNumber</span> <span style="color: #002200;">*</span>ableToBeCopied <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #400080;">NSNumber</span> numberWithBool<span style="color: #002200;">:</span><span style="color: #a61390;">YES</span><span style="color: #002200;">&#93;</span>;
&nbsp;
    <span style="color: #11740a; font-style: italic;">// However, ubiquitous items that are not downloaded CANNOT be copied</span>
    <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">&#91;</span>fm isUbiquitousItemAtURL<span style="color: #002200;">:</span>sourceFileURL<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
        <span style="color: #002200;">&#91;</span>sourceFileURL getResourceValue<span style="color: #002200;">:&amp;</span>ableToBeCopied forKey<span style="color: #002200;">:</span>NSURLUbiquitousItemIsDownloadedKey error<span style="color: #002200;">:</span><span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#125;</span>
&nbsp;
    <span style="color: #11740a; font-style: italic;">// Now copy the file if it doesn't exist and is able to be copied</span>
    <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">!</span><span style="color: #002200;">&#91;</span>fm fileExistsAtPath<span style="color: #002200;">:</span><span style="color: #002200;">&#91;</span>destFileURL path<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span> <span style="color: #002200;">&amp;&amp;</span> <span style="color: #002200;">&#91;</span>ableToBeCopied boolValue<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
        <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span><span style="color: #002200;">!</span><span style="color: #002200;">&#91;</span>fm copyItemAtURL<span style="color: #002200;">:</span>sourceFileURL toURL<span style="color: #002200;">:</span>destFileURL error<span style="color: #002200;">:&amp;</span>mergeError<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
            NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;ERROR (copy error): %@ -&gt; %@ - %@&quot;</span>, sourceFileURL, destFileURL, mergeError<span style="color: #002200;">&#41;</span>;
        <span style="color: #002200;">&#125;</span>
    <span style="color: #002200;">&#125;</span>
<span style="color: #002200;">&#125;</span></pre>
</div>
</div>
<h3>Conclusion</h3>
<p>See what I mean? Pretty obvious, and I can&#8217;t believe I lost so much time tracking this down. If the source file is ubiquitous, it might not be downloaded, and thus you might not be able to copy it. So check it first.</p>
]]></content:encoded>
			<wfw:commentRss>http://colonelpanic.net/2012/01/ios-and-icloud-overcoming-bad-file-descriptor-errors/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>UPDATED: Terminal Nirvana with TotalTerminal (Snow Leopard, Lion)</title>
		<link>http://colonelpanic.net/2011/08/updated-terminal-nirvana-with-totalterminal-snow-leopard-lion/</link>
		<comments>http://colonelpanic.net/2011/08/updated-terminal-nirvana-with-totalterminal-snow-leopard-lion/#comments</comments>
		<pubDate>Tue, 30 Aug 2011 05:08:30 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[General Development]]></category>
		<category><![CDATA[Systems Administration]]></category>
		<category><![CDATA[terminal]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[visor]]></category>

		<guid isPermaLink="false">http://colonelpanic.net/?p=537</guid>
		<description><![CDATA[It&#8217;s been a while since I wrote up how I achieved Terminal Nirvana on Snow Leopard using SIMBL and Visor. Since then, some things have changed: TotalTerminal has replaced Visor Mac OS X Lion has been released TotalTerminal changes up the way it launches Terminal &#8212; instead of being automatically injected via SIMBL, it manually [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s been a while since I wrote up how I achieved <a title="Terminal Nirvana on Snow Leopard with SIMBL + Visor" href="http://colonelpanic.net/2010/07/terminal-nirvana-on-snow-leopard-with-simbl-visor/">Terminal Nirvana on Snow Leopard using SIMBL and Visor</a>. Since then, some things have changed:</p>
<ul>
<li><a href="http://totalterminal.binaryage.com/">TotalTerminal</a> has replaced Visor</li>
<li>Mac OS X Lion has been released</li>
</ul>
<p>TotalTerminal changes up the way it launches Terminal &#8212; instead of being automatically injected via SIMBL, it manually injects the plugin into Terminal.app. Well, I wasn&#8217;t going to let this deter me.</p>
<p>Getting back to Nirvana after installing TotalTerminal is not all that bad. Most of the steps haven&#8217;t changed from my original post so I will only go into detail about the new steps here. Briefly, here are the steps I followed.</p>
<ol>
<li>Remove TerminalColours.bundle SIMBL plugin &#8212; per the <a href="http://totalterminal.binaryage.com/#faq">TotalTerminal FAQ</a>, it injects its own version and having TerminalColours.bundle installed creates a conflict. (~/Library/Application\ Support/SIMBL/Plugins)</li>
<li>Fix the Home / End keys (see original post)</li>
<li>Copy Terminal.app to VisorTerminal.app (see original post)</li>
<li>Install TotalTerminal</li>
<li>Modify TotalTerminal to use VisorTerminal.app instead of Terminal.app</li>
</ol>
<h3>That&#8217;s right, there&#8217;s really only one thing to change, and it&#8217;s very simple</h3>
<p>TotalTerminal.app has a simple, compiled AppleScript which launches Terminal and injects itself. The compiled file is located at /Applications/TotalTerminal.app/Contents/Resources/Scripts/main.scpt. But, we don&#8217;t want the compiled binary version, we want the original so we can make it use VisorTerminal.app.</p>
<p>Fortunately the <a href="https://raw.github.com/binaryage/totalterminal-installer/master/TotalTerminal.app/Contents/Resources/Scripts/main.applescript">uncompiled source file</a> is available in the <a href="https://github.com/binaryage/totalterminal-installer">TotalTerminal repo on Github</a>.</p>
<p>Only one change is necessary.</p>
<div class="wp_syntax">
<div class="code">
<pre class="diff" style="font-family:monospace;"><span style="color: #888822;">--- TotalTerminal.app/Contents/Resources/Scripts/main.applescript</span>
<span style="color: #888822;">+++ TotalTerminal.app/Contents/Resources/Scripts/main.applescript</span>
<span style="color: #440088;">@@ -1,4 +1,4 @@</span>
<span style="color: #991111;">-tell application &quot;Terminal&quot;</span>
<span style="color: #00b000;">+tell application &quot;VisorTerminal&quot;</span>
        delay <span style="">1</span> -- this delay is important to prevent random &quot;Connection is Invalid -<span style="">609</span>&quot; AppleScript errors
        try
                event BATTinit</pre>
</div>
</div>
<p>Once that is done, you just need to compile the script and replace the one that shipped with TotalTerminal.</p>
<div class="wp_syntax">
<div class="code">
<pre class="bash" style="font-family:monospace;">$ osacompile <span style="color: #660033;">-o</span> main.scpt main.applescript
$ <span style="color: #c20cb9; font-weight: bold;">mv</span> main.scpt <span style="color: #000000; font-weight: bold;">/</span>Applications<span style="color: #000000; font-weight: bold;">/</span>TotalTerminal.app<span style="color: #000000; font-weight: bold;">/</span>Contents<span style="color: #000000; font-weight: bold;">/</span>Resources<span style="color: #000000; font-weight: bold;">/</span>Scripts</pre>
</div>
</div>
<h3>That&#8217;s it.</h3>
<p>You should be good to go. Put TotalTerminal.app into your user startup applications if you wish (I do), or launch it manually by launching TotalTerminal.app.</p>
<p>Enjoy the restoration of terminal nirvana.</p>
<h3>For the lazy&#8230;</h3>
<p>My modified and compiled main.applescript is <a href="http://colonelpanic.net/wp-content/uploads/2011/08/modified-applescript-compiled.zip">available for download</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://colonelpanic.net/2011/08/updated-terminal-nirvana-with-totalterminal-snow-leopard-lion/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Enabling git access via password authentication with gitolite</title>
		<link>http://colonelpanic.net/2011/03/enabling-git-access-via-password-authentication-with-gitolite/</link>
		<comments>http://colonelpanic.net/2011/03/enabling-git-access-via-password-authentication-with-gitolite/#comments</comments>
		<pubDate>Fri, 04 Mar 2011 23:46:17 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[General Development]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[gitolite]]></category>
		<category><![CDATA[ssh]]></category>

		<guid isPermaLink="false">http://colonelpanic.net/?p=486</guid>
		<description><![CDATA[We recently started using gitolite at my workplace. Our previous git hosting setup involved manually managing linux users and groups on the Ubuntu server, which was needlessly time consuming and painful. There were times when file permissions got out of sync because the repo was deployed by user X from his workstation (where group permissions [...]]]></description>
			<content:encoded><![CDATA[<p>We recently started using <a title="gitolite" href="https://github.com/sitaramc/gitolite">gitolite</a> at my workplace. Our previous git hosting setup involved manually managing linux users and groups on the Ubuntu server, which was needlessly time consuming and painful. There were times when file permissions got out of sync because the repo was deployed by user X from his workstation (where group permissions were not setup correctly for a shared git repository), and other headaches.</p>
<p>We needed something easier. We did not want to go to a workflow where there is one git user on the system, every employee authenticates with their own public key to that user, and everyone with a key has access to everything. We wanted more granular control, but also an easier management workflow. While gitolite does use a single system user under the covers, it provides per-user access control (governed by public keys), easy repo management, and a couple other nice features like wildcard repositories and branch-level access restrictions.</p>
<p>However, one of our developers is in the habit of accessing a random server, cloning a repo (using his password), and pushing from environments other than his development environment. Obviously, his private key is not going to be on each of the machines he does this from. Gitolite does not allow password-based access for obvious reasons &#8212; it needs to know who you are to determine permissions &#8212; so gitolite was cramping his style.</p>
<p><span id="more-486"></span></p>
<p>There are a couple ways around this:</p>
<ol>
<li>Add a public key for each system he pushes changes from. Since he often logs in as &#8220;administrator&#8221; or &#8220;root&#8221; on individual systems, this obviously is not a good solution.</li>
<li>Have the developer enable SSH Agent Forwarding from his machine. This works well, as long as the user does not chain sessions (connect to server A, from there to server B, and clone on B) or is willing / able / allowed to enable Agent Forwarding on each system in the chain. (NOTE: on Mac OS X Snow Leopard, enabling SSH Agent Forwarding is as simple as running ssh-add and adding two lines to your ~/.ssh/config file:
<div class="wp_syntax">
<div class="code">
<pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># add key to agent (I do this in ~/.profile)</span>
<span style="color: #c20cb9; font-weight: bold;">ssh-add</span> <span style="color: #007800;">$HOME</span><span style="color: #000000; font-weight: bold;">/</span>.ssh<span style="color: #000000; font-weight: bold;">/</span>id_rsa
&nbsp;
<span style="color: #666666; font-style: italic;"># ~/.ssh/config</span>
Host <span style="color: #000000; font-weight: bold;">*</span>
    ForwardAgent <span style="color: #c20cb9; font-weight: bold;">yes</span></pre>
</div>
</div>
</li>
<li>Come up with something else.</li>
</ol>
<p>What we really wanted was a way to allow password-based access to the repositories. Since gitolite does not support this itself, we had to come up with another way. As it turns out, doing so is not too bad, though it does involve a little bash shell black magic.</p>
<p>What we came up with is creating a system user on the git server for each developer who wants password access to git repositories, using a custom script as their defined shell (instead of /bin/sh or /bin/bash). Don&#8217;t forget to make your new script executable.</p>
<p>This script needs to look at what the user is trying to do (git action, gitolite ADC, some random shell command, nothing&#8230;) and act accordingly. Here&#8217;s the script we came up with, which will be dissected below to explain what each part does in more detail than the inline doc (<a href="https://gist.github.com/847755">gist</a>).</p>
<div class="wp_syntax">
<div class="code">
<pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
<span style="color: #7a0874; font-weight: bold;">shift</span> <span style="color: #666666; font-style: italic;"># get rid of -c</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># if no commands, just open a shell</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$#</span> <span style="color: #660033;">-eq</span> <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">bash</span> <span style="color: #660033;">-l</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># if the first arg is a git- command, that means it is something like git-push, etc... so forward it</span>
<span style="color: #000000; font-weight: bold;">elif</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$1</span> == git-<span style="color: #000000; font-weight: bold;">*</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #c20cb9; font-weight: bold;">ssh</span> <span style="color: #660033;">-q</span> <span style="color: #660033;">-o</span> <span style="color: #007800;">UserKnownHostsFile</span>=<span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null <span style="color: #660033;">-o</span> <span style="color: #007800;">StrictHostKeyChecking</span>=no <span style="color: #c20cb9; font-weight: bold;">git</span><span style="color: #000000; font-weight: bold;">@</span>localhost <span style="color: #007800;">$*</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># if the first arg is SET_ENV_ONLY, we sourced this file in order to set up the gitolite function</span>
<span style="color: #000000; font-weight: bold;">elif</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$1</span> == <span style="color: #ff0000;">&quot;SET_ENV_ONLY&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
        gitolite <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
                <span style="color: #c20cb9; font-weight: bold;">ssh</span> <span style="color: #660033;">-q</span> <span style="color: #660033;">-o</span> <span style="color: #007800;">UserKnownHostsFile</span>=<span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null <span style="color: #660033;">-o</span> <span style="color: #007800;">StrictHostKeyChecking</span>=no <span style="color: #c20cb9; font-weight: bold;">git</span><span style="color: #000000; font-weight: bold;">@</span>localhost <span style="color: #007800;">$*</span>
        <span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># if there is at least one non-git command, source this file in a new shell and create the 'gitolite' function</span>
<span style="color: #000000; font-weight: bold;">else</span>
        <span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">bash</span> <span style="color: #660033;">-c</span> <span style="color: #ff0000;">&quot;source $0 shiftme SET_ENV_ONLY; $*&quot;</span>
<span style="color: #000000; font-weight: bold;">fi</span></pre>
</div>
</div>
<p>If the user is not trying to <em>do</em> anything (just wants to open a shell), then there are no arguments and we should just open a bash prompt:</p>
<div class="wp_syntax">
<div class="code">
<pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$#</span> <span style="color: #660033;">-eq</span> <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">bash</span> <span style="color: #660033;">-l</span></pre>
</div>
</div>
<p>Okay, the simple bit is out of the way. Now on to the black magic.</p>
<p>If the user is trying to perform a git command (via git push, etc.) then we create a new SSH session to localhost (remember, this is running on the same server as gitolite) and pass along the commands ($*). Since the user has already logged in, this ssh command will run from their account using their private / public key. The git commands are things like git-receive-pack, git-upload-pack, etc, so we match the first script argument against &#8220;git-&#8221;.</p>
<p>Finally, we don&#8217;t care about validating the host&#8217;s fingerprint (we are already on the host) and there can be no man in the middle (since we are going to localhost), so we can turn off StrictHostKeyChecking. We also don&#8217;t want to print out the various fingerprint messages that SSH will generate when you ignore host keys, so we make the new SSH connection quiet. That&#8217;s it for this block:</p>
<div class="wp_syntax">
<div class="code">
<pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">elif</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$1</span> == git-<span style="color: #000000; font-weight: bold;">*</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #c20cb9; font-weight: bold;">ssh</span> <span style="color: #660033;">-q</span> <span style="color: #660033;">-o</span> <span style="color: #007800;">UserKnownHostsFile</span>=<span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null <span style="color: #660033;">-o</span> <span style="color: #007800;">StrictHostKeyChecking</span>=no <span style="color: #c20cb9; font-weight: bold;">git</span><span style="color: #000000; font-weight: bold;">@</span>localhost <span style="color: #007800;">$*</span></pre>
</div>
</div>
<p>I am going to go over the last two pieces in reverse order, because it is easier to follow.</p>
<p>If the user sent some SSH commands that were <strong>not</strong> native git commands, we need to process those commands. So, we will execute the remaining commands in a new bash process.</p>
<p>BUT, what if the user is trying to perform a gitolite command (such as <em>expand</em> or an ADC), what should we do? We can&#8217;t just trust that all commands the user sends will either be a git command or a gitolite command, so we need to set up some more black magic to handle that for us. So the first thing we will do when we open a new bash process to handle the remaining commands is source <strong>this custom script</strong> ($0) with a custom value we made up (SET_ENV_ONLY). That way, if this script executes again we will know it was done by ourselves and we can set up some more magic.</p>
<div class="wp_syntax">
<div class="code">
<pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">else</span>
        <span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">bash</span> <span style="color: #660033;">-c</span> <span style="color: #ff0000;">&quot;source $0 shiftme SET_ENV_ONLY; $*&quot;</span></pre>
</div>
</div>
<p>Finally for the last block.</p>
<p>If our new script is being executed, and the first argument is SET_ENV_ONLY (after <em>shift</em>ing), then it is because we sourced it from our new bash process from the previous step. What we do now is set up a <em>gitolite</em> command which does something very similar to what happens if the user is performing a native git command: it opens an SSH connection to git@host and performs the gitolite commands.</p>
<p>After this has been done, &#8220;gitolite expand&#8221; is the same as &#8220;ssh git@git.company.com expand&#8221;. This makes it so the developer can still run gitolite commands and ADCs, he just has to prefix each command with <em>gitolite</em>. Something like this:</p>
<div class="wp_syntax">
<div class="code">
<pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">ssh</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>DEVELOPER<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #000000; font-weight: bold;">@</span>git.company.com <span style="color: #ff0000;">&quot;gitolite expand; echo <span style="color: #007800;">$PATH</span>; gitolite info&quot;</span></pre>
</div>
</div>
<p>is equivalent to this:</p>
<div class="wp_syntax">
<div class="code">
<pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">ssh</span> <span style="color: #c20cb9; font-weight: bold;">git</span><span style="color: #000000; font-weight: bold;">@</span>git.company.com expand
$ <span style="color: #c20cb9; font-weight: bold;">ssh</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>DEVELOPER<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #000000; font-weight: bold;">@</span>git.company.com <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$PATH</span>
$ <span style="color: #c20cb9; font-weight: bold;">ssh</span> <span style="color: #c20cb9; font-weight: bold;">git</span><span style="color: #000000; font-weight: bold;">@</span>git.company.com info</pre>
</div>
</div>
<p>Now you just need to create accounts that use this script as their shell. Each user can add whatever public keys they want to their authorized_keys file, or they can authenticate solely with their password. The only requirement is that their server account has a private / public key generated, and that the public key is added to gitolite.</p>
<div class="wp_syntax">
<div class="code">
<pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">ssh</span> root<span style="color: #000000; font-weight: bold;">@</span>git.company.com
$ useradd <span style="color: #660033;">-s</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>custom_gitbash.sh <span style="color: #660033;">-m</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>DEVELOPER<span style="color: #7a0874; font-weight: bold;">&#93;</span>
$ <span style="color: #c20cb9; font-weight: bold;">su</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>DEVELOPER<span style="color: #7a0874; font-weight: bold;">&#93;</span>
$ <span style="color: #c20cb9; font-weight: bold;">ssh-keygen</span> <span style="color: #660033;">-t</span> rsa
$ <span style="color: #c20cb9; font-weight: bold;">cp</span> ~<span style="color: #000000; font-weight: bold;">/</span>.ssh<span style="color: #000000; font-weight: bold;">/</span>id_rsa.pub ~<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">&#91;</span>DEVELOPER<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #000000; font-weight: bold;">@</span>git.company.com.pub
<span style="color: #666666; font-style: italic;"># add the new public key to the gitolite keydir</span></pre>
</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://colonelpanic.net/2011/03/enabling-git-access-via-password-authentication-with-gitolite/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Solr DisMax gotchas: fun with stopwords and punctuation</title>
		<link>http://colonelpanic.net/2010/09/solr-dismax-gotchas-fun-with-stopwords-and-punctuation/</link>
		<comments>http://colonelpanic.net/2010/09/solr-dismax-gotchas-fun-with-stopwords-and-punctuation/#comments</comments>
		<pubDate>Sat, 18 Sep 2010 05:16:42 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[General Development]]></category>
		<category><![CDATA[dismax]]></category>
		<category><![CDATA[solr]]></category>
		<category><![CDATA[stopwords]]></category>

		<guid isPermaLink="false">http://colonelpanic.net/?p=405</guid>
		<description><![CDATA[I have been using Apache Solr on a recent project for my employer, and ran into some gotchas. Notably, I had issues with a DisMax query not working the way I expected because of inconsistent stopwords configuration on the fields being searched. I also ran into a problem with words being tokenized with their surrounding punctuation, [...]]]></description>
			<content:encoded><![CDATA[<p>I have been using <a href="http://lucene.apache.org/solr/">Apache Solr</a> on a recent project for my employer, and ran into some gotchas. Notably, I had issues with a DisMax query not working the way I expected because of inconsistent stopwords configuration on the fields being searched.</p>
<p>I also ran into a problem with words being tokenized with their surrounding punctuation, rather than simply the word &#8212; searching for &#8220;something&#8221; was definitely NOT the same thing as searching for &#8220;something.&#8221; &#8212; note the included punctuation in the second search.</p>
<p>The bottom line:</p>
<ul>
<li>make sure stopwords is configured the same way for the fields you are searching (or at least be sure you understand the ramifications)</li>
<li>don&#8217;t be afraid to play with the &#8220;minimum-match&#8221; (mm) default configuration</li>
<li>when it makes sense, strip surrounding punctuation using PatternReplaceFilterFactory using an index tokenizer</li>
</ul>
<p>For the full, detailed write-up, head over to OpenSky&#8217;s engineering blog and read the <a href="http://engineering.shopopensky.com/post/creating-a-unified-search-experience">original blog post</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://colonelpanic.net/2010/09/solr-dismax-gotchas-fun-with-stopwords-and-punctuation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dynamic HTML content in iTunes LP / iTunes Extras</title>
		<link>http://colonelpanic.net/2010/08/dynamic-html-content-in-itunes-lp-itunes-extras/</link>
		<comments>http://colonelpanic.net/2010/08/dynamic-html-content-in-itunes-lp-itunes-extras/#comments</comments>
		<pubDate>Wed, 18 Aug 2010 03:58:41 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[General Development]]></category>
		<category><![CDATA[apple]]></category>
		<category><![CDATA[itunes]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://colonelpanic.net/?p=332</guid>
		<description><![CDATA[Recently, I have been doing some iTunes LP projects for one of my clients. One of the things that immediately struck me as a huge potential time saver was automating the creation of HTML elements for lists of items, ie lists of song and video tracks. Often I can splice images such that their position [...]]]></description>
			<content:encoded><![CDATA[<p>Recently, I have been doing some iTunes LP projects for one of my clients. One of the things that immediately struck me as a huge potential time saver was automating the creation of HTML elements for lists of items, ie lists of song and video tracks. Often I can splice images such that their position can be controlled with a single CSS rule, and explicitly creating all the <em>image-fader</em> DIVs for the individual songs or videos in the HTML views is terribly redundant.</p>
<h2>The Goal</h2>
<p>Create HTML elements dynamically which transition appropriately when the view controller appears.</p>
<h2>The Problem</h2>
<p>The shipping version of TuneKit.js doesn&#8217;t give you a chance to append elements to the DOM before viewDidAppear is invoked (which is after transitionToController).</p>
<p><span id="more-332"></span></p>
<h2>Initial Attempts</h2>
<p>I first tried appending the child elements (using TKUtils.buildElement in a loop over appData.songs) inside the viewDidAppear callback. Obviously, the problem here is that the elements don&#8217;t exist the first time the view controller appears, so can&#8217;t nicely fade in via your defined CSS animations.</p>
<p>Next, I tried moving the logic that create the HTML elements into viewWillAppear. The problem here was that this method was called before the desired view controller is added to the DOM &#8212; so the element I need to append the children to doesn&#8217;t exist.</p>
<h2>The Solution</h2>
<p>The solution was actually pretty simple, and works like a charm; you just need to be willing to edit TuneKit.js.<br />
<!--more--><br />
Before:</p>
<div class="wp_syntax">
<div class="code">
<pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// pre-transition methods</span>
controller._viewWillAppear<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
controller.<span style="color: #660066;">viewWillAppear</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// add it to the tree</span>
<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">view</span>.<span style="color: #660066;">appendChild</span><span style="color: #009900;">&#40;</span>controller.<span style="color: #660066;">view</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// transition</span>
<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>previous_controller <span style="color: #339933;">!==</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">transitionToController</span><span style="color: #009900;">&#40;</span>previous_controller<span style="color: #339933;">,</span> controller<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre>
</div>
</div>
<p>After:</p>
<div class="wp_syntax">
<div class="code">
<pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// add it to the tree</span>
<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">view</span>.<span style="color: #660066;">appendChild</span><span style="color: #009900;">&#40;</span>controller.<span style="color: #660066;">view</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// pre-transition methods</span>
controller._viewWillAppear<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
controller.<span style="color: #660066;">viewWillAppear</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// transition</span>
<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>previous_controller <span style="color: #339933;">!==</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">transitionToController</span><span style="color: #009900;">&#40;</span>previous_controller<span style="color: #339933;">,</span> controller<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre>
</div>
</div>
<h2>Conclusion</h2>
<p>Now that TuneKit appends the view controller to the DOM before calling the viewWillAppear callback, your dynamic elements can be created before the view appears and transitionToController is invoked.</p>
<p>Done.</p>
]]></content:encoded>
			<wfw:commentRss>http://colonelpanic.net/2010/08/dynamic-html-content-in-itunes-lp-itunes-extras/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<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>

