<?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>bloggo ergo sum &#187; shell</title>
	<atom:link href="http://bloggoergosum.com/tag/shell/feed/" rel="self" type="application/rss+xml" />
	<link>http://bloggoergosum.com</link>
	<description></description>
	<lastBuildDate>Thu, 15 Mar 2012 05:47:53 +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>Useful Git Prompt</title>
		<link>http://bloggoergosum.com/2008/04/12/useful-git-prompt/</link>
		<comments>http://bloggoergosum.com/2008/04/12/useful-git-prompt/#comments</comments>
		<pubDate>Sat, 12 Apr 2008 19:42:08 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://bloggoergosum.us/?p=304</guid>
		<description><![CDATA[Here&#8217;s a snippet of bash script that I wrote to make my prompt tell me when I&#8217;m in a git repository and what branch I&#8217;m on. And to my pleasant surprise, the PROMPT_COMMAND mechanism will respect color codes, so if you have your branch listings in git colorized, it will be reflected in your prompt. <a href="http://bloggoergosum.com/2008/04/12/useful-git-prompt/"> read more <span class="meta-nav">&#187;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a snippet of bash script that I wrote to make my prompt tell me when I&#8217;m in a git repository and what branch I&#8217;m on.</p>
<p>And to my pleasant surprise, the PROMPT_COMMAND mechanism will respect color codes, so if you have your branch listings in git colorized, it will be reflected in your prompt.</p>
<pre lang="bash">
function rfind
{
    dir=$PWD
    while [ ! -e $1 ]; do
        if [ $PWD == "/" ]; then
            command cd $dir
            return 1
        else
            command cd ..
        fi
    done

    rfdir=$PWD
    command cd $dir

    return 0
}

function git_dir
{
     typeset str
     rfdir=""
     rfind '.git'
     if [ $? -eq 0 ]; then
        str="{`git branch | grep '*' | cut -d ' ' -f 2`}"
        rfdir=`echo $rfdir | sed "s#$HOME#~#"`
     fi

    echo "$str"
}

function mkprompt
{
    typeset branch
    branch=`git_dir`
    PS1="${branch}$ "
}

PROMPT_COMMAND=mkprompt
export PROMPT_COMMAND
</pre>
]]></content:encoded>
			<wfw:commentRss>http://bloggoergosum.com/2008/04/12/useful-git-prompt/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

