<?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>Journal of a Maker &#187; Unix</title>
	<atom:link href="http://www.warrenmoore.net/blog/category/unix/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.warrenmoore.net/blog</link>
	<description>a blog by Warren C. Moore</description>
	<lastBuildDate>Fri, 18 Jun 2010 22:00:32 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Make Terminal Follow Aliases Like Symlinks</title>
		<link>http://www.warrenmoore.net/blog/2010/01/09/make-terminal-follow-aliases-like-symlinks/</link>
		<comments>http://www.warrenmoore.net/blog/2010/01/09/make-terminal-follow-aliases-like-symlinks/#comments</comments>
		<pubDate>Sat, 09 Jan 2010 21:34:49 +0000</pubDate>
		<dc:creator>warren</dc:creator>
				<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[Unix]]></category>

		<guid isPermaLink="false">http://www.warrenmoore.net/blog/?p=22</guid>
		<description><![CDATA[Okay, so you&#8217;re spelunking around in Mac OS using Terminal. You try to &#8216;cd&#8217; into a directory only to be told that what you&#8217;re trying to get to &#8220;is not a directory.&#8221; Then you remember that the target directory is actually a shortcut that you created with Finder. It looks just link a symlink in [...]]]></description>
			<content:encoded><![CDATA[<p><em><span style="font-style: normal;">Okay, so you&#8217;re spelunking around in Mac OS using Terminal. You try to &#8216;cd&#8217; into a directory only to be told that what you&#8217;re trying to get to &#8220;is not a directory.&#8221; Then you remember that the target directory is actually a shortcut that you created with Finder. It looks just link a symlink in Finder, so shouldn&#8217;t it act like one in Terminal?</span></em></p>
<p><em> </em></p>
<p><span style="font-style: normal;">Unfortunately, in OS X, aliases are treated differently by the command line than symlinks. In particular, they won&#8217;t be followed by the &#8220;cd&#8221; command, leading to your present frustration. Fortunately, with a little elbow grease, you can patch up your shell and be on your merry way.<span id="more-22"></span></span></p>
<p><span style="font-style: normal;">This is a two-part process requiring a little familiarity with gcc and bash, but I&#8217;ll try to make it as simple as possible. Firstly, you need this file: </span><a title="getTrueName.c" href="http://www.macosxhints.com/dlfiles/getTrueName.txt" target="_blank"><span style="font-style: normal;">getTrueName.c</span></a><span style="font-style: normal;">. This file was created by Thos Davis and is licensed under the GPLv2. Save it anywhere, then compile it with the following command:</span></p>
<pre><span style="font-style: normal;">gcc -o getTrueName -framework Carbon getTrueName.c</span></pre>
<p><span style="font-style: normal;">This will create the &#8216;getTrueName&#8217; executable in the same directory as the source. You can add it to your PATH, or just copy it directly to /usr/bin so it&#8217;s easy to access.</span></p>
<p><span style="font-style: normal;">Interestingly, when Terminal opens a new shell, .bashrc is not executed as you might expect. Instead, under the login shell, .bash_profile is executed. So, add the following to .bash_profile in your Home directory. You might need to create it first; it isn&#8217;t there by default.</span></p>
<pre class="brush: bash;">function cd {
  if [ ${#1} == 0 ]; then
    builtin cd
  elif [ -d &quot;${1}&quot; ]; then
    builtin cd &quot;${1}&quot;
  elif [[ -f &quot;${1}&quot; || -L &quot;${1}&quot; ]]; then
    path=$(getTrueName &quot;$1&quot;)
    builtin cd &quot;$path&quot;
  else
    builtin cd &quot;${1}&quot;
  fi
}
</pre>
<p><span style="font-style: normal;">Effectively, this looks for Finder aliases and resolves them before deferring to the builtin cd command. Append it to your .bash_profile, then either execute it or restart Terminal for the changes to take effect. Now you can cd to Finder aliases within Terminal and have them treated just like symlinks. Just like it should be.</span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.warrenmoore.net/blog/2010/01/09/make-terminal-follow-aliases-like-symlinks/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
