<?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>Michael V. O'Brien &#187; Uncategorized</title>
	<atom:link href="http://michaelobrien.info/blog/category/uncategorized/feed/" rel="self" type="application/rss+xml" />
	<link>http://michaelobrien.info/blog</link>
	<description></description>
	<lastBuildDate>Wed, 27 Jan 2010 04:46:55 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>A &#8216;cd&#8217; Command for Git Projects</title>
		<link>http://michaelobrien.info/blog/2009/01/a-cd-command-for-git-projects/</link>
		<comments>http://michaelobrien.info/blog/2009/01/a-cd-command-for-git-projects/#comments</comments>
		<pubDate>Tue, 20 Jan 2009 20:26:28 +0000</pubDate>
		<dc:creator>michael</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[git]]></category>

		<guid isPermaLink="false">http://michaelobrien.info/blog/?p=28</guid>
		<description><![CDATA[I often find myself in a project directory and one of two things usually happens.  The first is that I would like to go directly to the top level directory of the project.  The second is that I would like to go outside of the project directory and get back very quickly.  [...]]]></description>
			<content:encoded><![CDATA[<p>I often find myself in a project directory and one of two things usually happens.  The first is that I would like to go directly to the top level directory of the project.  The second is that I would like to go outside of the project directory and get back very quickly.  Though not sophisticated, I came up with this simple shell script called <b>cd-to-project-root</b>.</p>
<pre class="code">
<span class="comment-delimiter">#</span><span class="comment">!/bin/</span><span class="keyword">sh</span><span class="comment">
</span>
pushd . &gt; /dev/null

<span class="keyword">until</span> [ -d .git ] || [ <span class="sh-quoted-exec">`pwd`</span> = <span class="string">'/'</span> ]; <span class="keyword">do</span>
    <span class="builtin">cd</span> ..;
<span class="keyword">done</span>

<span class="keyword">if</span> [ <span class="sh-quoted-exec">`pwd`</span> = <span class="string">'/'</span> ]; <span class="keyword">then</span>  <span class="comment-delimiter"># </span><span class="comment">try to go to a project directory
</span>    <span class="keyword">if</span> [ -z $<span class="variable-name">PREV_PROJECT_ROOT</span> ]; <span class="keyword">then</span>
        popd &gt; /dev/null
        <span class="builtin">echo</span> <span class="string">"Project directory not found."</span>;
    <span class="keyword">else</span>
        <span class="builtin">cd</span> $<span class="variable-name">PREV_PROJECT_ROOT</span>
    <span class="keyword">fi</span>
<span class="keyword">else</span>  <span class="comment-delimiter"># </span><span class="comment">at a project directory
</span>    <span class="builtin">export</span> <span class="variable-name">PREV_PROJECT_ROOT</span>=<span class="sh-quoted-exec">`pwd`</span>
<span class="keyword">fi</span>
</pre>
<p> <!-- End class="code" --></p>
<p>I saved this in my &#8220;~/bin&#8221; directory and made an alias to it called <b>cdp</b>.  It&#8217;s important to source the script, otherwise the shell variables will not retain their values when the script terminates.</p>
<pre>
alias cdp=". cd-to-project-root"
</pre>
<p>This allows me to type <b>cdp</b> to set the project directory, which is under git version control.  Anytime I want to get back to the project directory, I type <b>cdp</b>.</p>
]]></content:encoded>
			<wfw:commentRss>http://michaelobrien.info/blog/2009/01/a-cd-command-for-git-projects/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
