<?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>furmanek.net &#187; Introductions</title>
	<atom:link href="http://www.furmanek.net/category/introductions/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.furmanek.net</link>
	<description>Greg Furmanek's personal blog</description>
	<lastBuildDate>Sat, 28 Aug 2010 18:58:10 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Unix prompt (PS1) with git branch name</title>
		<link>http://www.furmanek.net/39/unix-prompt-for-usage-with-git/</link>
		<comments>http://www.furmanek.net/39/unix-prompt-for-usage-with-git/#comments</comments>
		<pubDate>Mon, 14 Jul 2008 14:00:32 +0000</pubDate>
		<dc:creator>Gregory Furmanek</dc:creator>
				<category><![CDATA[Bash]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Introductions]]></category>
		<category><![CDATA[Unix]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[PS1]]></category>

		<guid isPermaLink="false">http://www.furmanek.net/?p=39</guid>
		<description><![CDATA[Working with Git I noticed that I change branches quite a lot.  This is a good thing but sometimes I am in the incorrect branch when I check things in.  I needed a warning system especially when I check things into remote SVN repository.  Since most of my check-ins are done from [...]]]></description>
			<content:encoded><![CDATA[<p>Working with Git I noticed that I change branches quite a lot.  This is a good thing but sometimes I am in the incorrect branch when I check things in.  I needed a warning system especially when I check things into remote SVN repository.  Since most of my check-ins are done from the command line it would be nice to know what branch I am on just by looking at the screen.  Fortunately there is neat way to add the branch information to the Unix prompt.  You can do that by overriding the PS1 variable for example:</p>
<pre>
export PS1="[\D{%Y-%m-%d} \t] \w \n$"
</pre>
<p>would generate</p>
<pre>
[2008-07-12 12:00:00] /foo/bar
$
</pre>
<p>if I am in the <code>/foo/bar</code> directory.</p>
<p>So at this point I would like the prompt to look like:</p>
<pre>
[2008-07-12 12:00:00] /foo/bar <span style="color:green;">[master]</span>
$
</pre>
<p>when I am in a master branch and prompt:</p>
<pre>
[2008-07-12 12:00:00] /foo/bar <span style="color:red;">[experimental]</span>
$
</pre>
<p>when I am in any other branch.</p>
<p>Here are the steps to get this working:<br />
Prerequisites:<br />
- ruby interpreter<br />
- git</p>
<p>Steps:</p>
<ol>
<li> Create a git-ps.rb file
<pre>
green = "\033[0;32m"
white = "\033[0;37m"
red   = "\033[0;31m"
current_branch = `git branch 2>/dev/null`.grep(/^\*/).first
if current_branch
  branch_name = current_branch.gsub(/^\*\s*/,'').strip
  color = branch_name  =~ /master/ ? green : red
  unless current_branch.empty?
    puts "  #{color}[#{branch_name}]#{white}"
  end
end
</pre>
</li>
<li> create .ps file in your home directory:
<pre>
parse_git_branch() {
  ruby ~/git-ps.rb 2>/dev/null
}
export PS1="[\D{%Y-%m-%d} \t] \w\$(parse_git_branch) \n$ "
</pre>
</li>
<li>Include the .ps file in your .bashrc and .bash_profile by inserting following line:
<pre>
. ~/.ps
</pre>
</li>
</ol>
<p>To activate the new prompt in your current execute command:<br />
. ~/.ps</p>
<p>I hope this helps.</p>
<hr/>
<p style="font-weight:bold">References</p>
<p>Ref: <a href="http://wiki.archlinux.org/index.php/Color_Bash_Prompt">Prompt Creation</a><br />
Ref: <a href="http://unboundimagination.com/Current-Git-Branch-in-Bash-Prompt">Git and Bash prompt</a><br />
Ref: <a href="http://blog.ericgoodwin.com/2008/4/10/auto-completion-with-git">__git_ps1</a></p>
<hr/>
<p style="font-weight:bold">Downloads</p>
<p><a href='http://www.furmanek.net/wp-content/uploads/2008/07/colored_branch_name.tgz'>colored_branch_name</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.furmanek.net/39/unix-prompt-for-usage-with-git/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>First Post</title>
		<link>http://www.furmanek.net/7/home/</link>
		<comments>http://www.furmanek.net/7/home/#comments</comments>
		<pubDate>Tue, 26 Jun 2007 02:54:27 +0000</pubDate>
		<dc:creator>Gregory Furmanek</dc:creator>
				<category><![CDATA[Introductions]]></category>

		<guid isPermaLink="false">http://www.furmanek.net/7/home/</guid>
		<description><![CDATA[Welcome to Furmanek.net.  This is my first post in a while, so I will keep it short.  I am intending to write much more content and discuss wide variety of subjects starting with technology (my favorite) through politics, religions, philosophy, psychology and some other lighter stuff.  I hope you will enjoy my [...]]]></description>
			<content:encoded><![CDATA[<p>Welcome to Furmanek.net.  This is my first post in a while, so I will keep it short.  I am intending to write much more content and discuss wide variety of subjects starting with technology (my favorite) through politics, religions, philosophy, psychology and some other lighter stuff.  I hope you will enjoy my writing and visit my site often.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.furmanek.net/7/home/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
