Enhance your prompt with git information
Git provides a series of enhancements for the bash prompt. It can display the current branch when inside a working copy. Here's an example from my machine:
{syntaxhighlighter brush: bash; gutter: false}
stefan@debian:~/Documents/Projects/Drupal/test(master *)$
{/syntaxhighlighter}
It shows the branch name and indicates by an asterisk that I have uncommitted changes.
On Debian based systems you can enable that feature in your .bashrc if you are using bash as your shell. It requires the package bash-completion which can be installed via apt-get install bash-completion
. On my system (Debian squeeze) I have a .bashrc file containing two prompt definitions (the lines starting with PS1). Whatever prompt you choose in your setup adding $(__git_ps1 "(%s)")
adds the branch info to the path if available:
{syntaxhighlighter brush: bash; gutter: false}
if [ "$color_prompt" = yes ]; then
PS1='${debian_chroot:+($debian_chroot)}[\033[01;32m]\u@\h[\033[00m]:[\033[01;34m]\w[\033[31m]$(__git_ps1 "(%s)")[\033[01;34m][\033[00m]\$ '
else
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w$(__git_ps1 "(%s)")\$ '
fi
{/syntaxhighlighter}
Not that you can modify the appearance of the git prompt. If you like to have curly braces around the branch name just replace the parentheses inside the quotes around %s.
There are some variables that enable additional features. In order to have bash indicate the state of your working copy add GIT_PS1_SHOWDIRTYSTATE=1
somewhere in .bashrc. Read /etc/bash_completion.d/git for more.
Comments
Post new comment