[Insight-developers] Bash shell prompt customization
Matthew McCormick (thewtex)
matt at mmmccormick.com
Mon Sep 27 15:38:54 EDT 2010
>
>
> I'm sure the experts already know this, but if you are using the bash
> shell, you can customize the prompt to show which git branch is
> active.
>
> Here is what I added to my ~/.bashrc file:
>
> parse_git_branch()
> {
> git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
> }
> export
> PS1="[\[\e[01;34m\]\W\[\e[31m\]\$(parse_git_branch)\[\e[00m\]]\[\e[00m\]
> "
>
>
Hi Bill,
This is a great tip.
Note that git already comes with some machinery to do this. Here is what
the relevant lines looks like in my .bashrc
source /usr/share/bash-completion/git
export
PS1='\[\033[01;32m\]\u\[\033[00;34m\]@\[\033[01;35m\]\h\[\033[01;36m\]
\w$(__git_ps1 " (%s)")\[\033[00;34m\]\$\[\033[00m\] '
There are tips in the comments of /usr/share/bash-completion/git for using
__git_ps1. There are a couple of customization available.
Matt
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/mailman/private/insight-developers/attachments/20100927/ad87e9ac/attachment.htm>
More information about the Insight-developers
mailing list