Thu 2010-09-02 ( En pr )

When you include this in your ~/.bash_login file:

# Show current git branch or SVN subfolder in prompt.
      GREEN="\[\033[0;32m\]"
LIGHT_GREEN="\[\033[1;32m\]"
       GRAY="\[\033[1;30m\]"
 LIGHT_BLUE="\[\033[1;34m\]"
 LIGHT_GRAY="\[\033[0;37m\]"
  COLOR_OFF="\[\e[0m\]"
function prompt_func() {
  branch_pattern="\* ([^$IFS]*)"
  PS1="$LIGHT_GRAY`date +%H:%M:%S`$COLOR_OFF $LIGHT_GREEN\w$COLOR_OFF"
  if [[ -d "./.git" && "$(git branch --no-color 2> /dev/null)" =~ $branch_pattern ]]; then
    branch="${BASH_REMATCH[1]}"
    PS1+=":$LIGHT_BLUE$branch$COLOR_OFF"
  elif [[ -d "./.svn" ]]; then
    path_pattern="URL: ([^$IFS]*).*Repository Root: ([^$IFS]*).*Revision: ([0-9]*)"
    if [[ "$(svn info 2> /dev/null)" =~ ${path_pattern} ]]; then
      branch=`/usr/bin/ruby -e 'print ARGV[0][ARGV[1].size + 1..-1] || "/"' ${BASH_REMATCH[1]} ${BASH_REMATCH[2]}`
      revision="${BASH_REMATCH[3]}"
      PS1+=":$LIGHT_BLUE$branch$GRAY@$revision$COLOR_OFF"
    fi
  fi
  PS1+=" "
}
PROMPT_COMMAND=prompt_func

…it should show you, depending on what kind of folder you’re in, the current git or svn branch:

~ cd ruby/coderay
~/ruby/coderay:trunk@644 cd ../coderay-0.9
~/ruby/coderay-0.9:branches/0.9@641 cd ~/studies/ikiwiki/
~/studies/ikiwiki:master 

It is quite fast, but needs Ruby (any idea for a bash-only version?)

Update: Fixed a few things.
Update 2: Cleanup, SVN revison number.

Say something! / Sag was!

Hey murphy :),

at the bottom of http://rbjl.net/21-rubybuntu-3-be-one-with-your-command-line is my version for a git prompt with ⚡, using only bash.
J-_-L @ 00:22 on Friday, 2010-09-03
Cool!  I think you can get rid of the '-d "./.git" &&', though -- otherwise you only see your branch in the git root directory.
Giles @ 16:57 on Wednesday, 2010-09-08
Giles: That's true, but it speeds up the prompt function when I'm *not* in a git directory. I also rarely leave the root directory.
murphy @ 12:25 on Sunday, 2010-09-12
Replace the Ruby line with this:

branch=`expr ${BASH_REMATCH[1]:\`expr match ${BASH_REMATCH[1]} ${BASH_REMATCH[2]}\`+1}
Greg Gaughan @ 14:55 on Wednesday, 2010-09-22
or even better:

branch=${BASH_REMATCH[1]##`expr ${BASH_REMATCH[2]}`}
Greg Gaughan @ 18:01 on Friday, 2010-09-24
excreetment excripte petteron
james xyalt common smyth contact @ 07:40 on Tuesday, 2012-05-15
load xscrepts dsc 1032943
james xyalt common smyth contact @ 07:41 on Tuesday, 2012-05-15
load benaik
james xyalt common smyth contact @ 07:41 on Tuesday, 2012-05-15
load crown 1634 875
james xyalt common smyth contact @ 07:41 on Tuesday, 2012-05-15
# Show current git branch or SVN subfolder in prompt.
      GREEN="\[\033[0;32m\]"
LIGHT_GREEN="\[\033[1;32m\]"
       GRAY="\[\033[1;30m\]"
 LIGHT_BLUE="\[\033[1;34m\]"
 LIGHT_GRAY="\[\033[0;37m\]"
  COLOR_OFF="\[\e[0m\]"
function prompt_func() {
  branch_pattern="\* ([^$IFS]*)"
  PS1="$LIGHT_GRAY`date +%H:%M:%S`$COLOR_OFF $LIGHT_GREEN\w$COLOR_OFF"
  if [[ -d "./.git" && "$(git branch --no-color 2> /dev/null)" =~ $branch_pattern ]]; then
    branch="${BASH_REMATCH[1]}"
    PS1+=":$LIGHT_BLUE$branch$COLOR_OFF"
  elif [[ -d "./.svn" ]]; then
    path_pattern="URL: ([^$IFS]*).*Repository Root: ([^$IFS]*).*Revision: ([0-9]*)"
    if [[ "$(svn info 2> /dev/null)" =~ ${path_pattern} ]]; then
      branch=`/usr/bin/ruby -e 'print ARGV[0][ARGV[1].size + 1..-1] || "/"' ${BASH_REMATCH[1]} ${BASH_REMATCH[2]}`
      revision="${BASH_REMATCH[3]}"
      PS1+=":$LIGHT_BLUE$branch$GRAY@$revision$COLOR_OFF"
    fi
  fi
  PS1+=" "
james xyalt common smyth contact @ 07:42 on Tuesday, 2012-05-15
Rattling great visual appeal on this web site, I'd value it 10. decfeekbfacadeee
Smitha568 @ 20:36 on Tuesday, 2016-12-20
Hello!<a href="http://www.cia9online.com/#1.html">cialis online pharmacy</a>
Pharme15 @ 11:17 on Wednesday, 2016-12-21
Hello! [url=http://www.cia9online.com/#2.html]cialis online pharmacy[/url]
Pharmb300 @ 11:17 on Wednesday, 2016-12-21
Hello! cialis online pharmacy http://www.cia9online.com/#4.html
Pharme189 @ 11:17 on Wednesday, 2016-12-21
Hello!
Pharmg152 @ 11:17 on Wednesday, 2016-12-21
Hello!<a href="http://www.cia9online.com/#1.html">online pharmacy cialis</a>
Pharmk375 @ 17:23 on Thursday, 2016-12-22
Hello! [url=http://www.cia9online.com/#2.html]online pharmacy cialis[/url]
Pharme464 @ 17:23 on Thursday, 2016-12-22
Hello! online pharmacy cialis http://www.cia9online.com/#4.html
Pharme501 @ 17:23 on Thursday, 2016-12-22
Hello!<a href="http://www.cia9online.com/#1.html">online pharmacy cialis</a>
Pharmf606 @ 23:48 on Friday, 2016-12-23
Hello! [url=http://www.cia9online.com/#2.html]online pharmacy cialis[/url]
Pharme852 @ 23:48 on Friday, 2016-12-23
Hello! online pharmacy cialis http://www.cia9online.com/#4.html
Pharme245 @ 23:48 on Friday, 2016-12-23
Hello!
Pharma58 @ 23:48 on Friday, 2016-12-23
Hello!<a href="http://www.cia9online.com/#1.html">cialis online pharmacy</a>
Pharma698 @ 06:02 on Sunday, 2016-12-25
Hello! [url=http://www.cia9online.com/#2.html]cialis online pharmacy[/url]
Pharmg242 @ 06:02 on Sunday, 2016-12-25
Hello! cialis online pharmacy http://www.cia9online.com/#4.html
Pharmk88 @ 06:02 on Sunday, 2016-12-25
Hello!
Pharma855 @ 06:03 on Sunday, 2016-12-25
Hello!<a href="http://www.cia9online.com/#1.html">cialis online pharmacy</a>
Pharmg380 @ 12:03 on Monday, 2016-12-26
Hello! [url=http://www.cia9online.com/#2.html]cialis online pharmacy[/url]
Pharme381 @ 12:03 on Monday, 2016-12-26
Hello!
Pharmd556 @ 12:03 on Monday, 2016-12-26
Hello!<a href="http://www.cia9online.com/#1.html">cialis online pharmacy</a>
Pharmd8 @ 18:05 on Tuesday, 2016-12-27
Hello! [url=http://www.cia9online.com/#2.html]cialis online pharmacy[/url]
Pharmd317 @ 18:05 on Tuesday, 2016-12-27
Hello! cialis online pharmacy http://www.cia9online.com/#4.html
Pharmf962 @ 18:06 on Tuesday, 2016-12-27
Hello!
Pharmg863 @ 18:07 on Tuesday, 2016-12-27
Hello!<a href="http://www.cia9online.com/#1.html">cialis online pharmacy</a>
Pharmd691 @ 00:10 on Thursday, 2016-12-29
Hello! [url=http://www.cia9online.com/#2.html]cialis online pharmacy[/url]
Pharmc532 @ 00:10 on Thursday, 2016-12-29
Hello! cialis online pharmacy http://www.cia9online.com/#4.html
Pharmk18 @ 00:10 on Thursday, 2016-12-29
Hello!
Pharmd539 @ 00:11 on Thursday, 2016-12-29

No markup, just plain monospace text. / Kein Markup, nur Normschrift-Klartext.