<?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>Claudio&#039;s Hideout &#187; programming</title>
	<atom:link href="http://claudio.cicali.name/post/tag/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://claudio.cicali.name</link>
	<description>Claudio Cicali web hub</description>
	<lastBuildDate>Sun, 25 Sep 2011 11:29:05 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>SVN customized bash prompt (and Git!)</title>
		<link>http://claudio.cicali.name/post/2010/02/svn-customized-bash-prompt/</link>
		<comments>http://claudio.cicali.name/post/2010/02/svn-customized-bash-prompt/#comments</comments>
		<pubDate>Tue, 09 Feb 2010 11:37:55 +0000</pubDate>
		<dc:creator>claudio</dc:creator>
				<category><![CDATA[Annunci]]></category>
		<category><![CDATA[Articoli]]></category>
		<category><![CDATA[Programmazione]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[english]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[svn]]></category>

		<guid isPermaLink="false">http://claudio.cicali.name/?p=650</guid>
		<description><![CDATA[I recently had to split an SVN repository of mine into a TRUNK and a TAGged branch. Nothing fancy: a tag to identify the REV1.x and the TRUNK to keep developing. From time to time I have to svn switch, jumping from the tagged branch to the trunk (testing, merging, usual staff&#8230;). And you know [...]]]></description>
			<content:encoded><![CDATA[<p>I recently had to split an SVN repository of mine into a TRUNK and a TAGged branch. Nothing fancy: a tag to identify the REV1.x and the TRUNK to keep developing.</p>
<p>From time to time I have to <strong>svn switch</strong>, jumping from the tagged branch to the trunk (testing, merging, usual staff&#8230;). And you know what? I&#8217;m keeping committing on the tagged branch! And that <strong>is bad</strong> (more on this with an appropriate future post. I promise).</p>
<p>How beautiful could be having a bash prompt that will costantly display the branch I&#8217;m in and the svn repository revision of the current directory?</p>
<p>So, here we are:</p>
<p>append this code to your ~/.bashrc, logout/login and enter a svn managed directory (beware: I&#8217;ve tested it only on my Ubuntu box&#8230; the key here is to use the PROMPT_COMMAND env variabile, passing it the function that does the &#8220;sniffing&#8221;. The PROMPT_COMMAND command will be executed every time, just before displaying the shell prompt).</p>
<pre class="brush: bash; gutter: false; title: ; notranslate">
PROMPT_COMMAND=prompt_command

prompt_command() {

  if [[ -d &quot;.svn&quot; ]] ; then
    local info rev url ver
    info=$(LC_MESSAGES=C svn info 2&gt;/dev/null)
    rev=$(echo &quot;${info}&quot; | awk '/^Revision: [0-9]+/{print $2}')
    url=$(echo &quot;${info}&quot; | awk '/^URL: .*/{print $2}')

    echo ${url} | grep -q &quot;/trunk\b&quot;
    if [[ $? -eq 0 ]] ; then
      ver=trunk
    else
      echo ${url} | grep -q &quot;/tags\b&quot;
      if [[ $? -eq 0 ]] ; then
        ver=tag-$(echo ${url} | grep -o &quot;/tags.*&quot; | awk -F/ '{print $3}')
      fi
    fi

    echo -e &quot;\e[00;33m[svn:r${rev}@${ver}]\e[00m&quot;
  fi

}
</pre>
<p>The svn information will be displayed in yellow (is the 33 in the final echo line). Change it at your liking.</p>
<p>UPDATE: <a href="http://www.develer.com">Giovanni Bajo</a> gives the hints for the "-q" switch and the LC_MESSAGES trick to avoid locale inconsistences.</p>
<p>Giovanni has gone a step forward, giving us the code for a git enhanced prompt too.</p>
<p>Here it is:</p>
<pre class="brush: bash; gutter: false; title: ; notranslate">
  local gitout
  gitout=$(git branch -v --abbrev --no-color 2&gt;/dev/null)
  if [[ $? -eq 0 ]]; then
    local full branch sha1
    full=$(echo &quot;${gitout}&quot; | grep '^*')
    branch=$(echo &quot;${full}&quot; | awk '/^* \w+ \w+/{print $2}')
    sha1=$(echo &quot;${full}&quot; | awk '/^* \w+ \w+/{print $3}')
    echo -e &quot;\e[00;33m[git:${sha1}@${branch}]\e[00m&quot;
  fi
</pre>
<p>Thanks to Uqbar on Freenode IRC for the awk hints!</p>
<p>example:</p>
<pre>claudioc@enebish:~/Sites$
claudioc@enebish:~/Sites$ cd scrive2/
[svn:r452@trunk]
claudioc@enebish:~/Sites/scrive2$ svn switch $myrepos/tags/R2.4
[svn:r431@tag-R2.4]
claudioc@enebish:~/Sites/scrive2$</pre>
]]></content:encoded>
			<wfw:commentRss>http://claudio.cicali.name/post/2010/02/svn-customized-bash-prompt/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>

