Posted on by | Posted in synyx Blog

Since Florian Hopf asked me today how I made my Bash prompt show the current git branch, here's the relevant .bashrc part (which evloved from code found on some other blogs I don't remember anymore).

function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'

function promptl {
local        BLUE="\[\033[0;34m\]"
local         RED="\[\033[0;31m\]"
local   LIGHT_RED="\[\033[1;31m\]"
local       GREEN="\[\033[0;32m\]"
local LIGHT_GREEN="\[\033[1;32m\]"
local       WHITE="\[\033[1;37m\]"
local  LIGHT_GRAY="\[\033[0;37m\]"
case $TERM in

$BLUE[$RED\$(date +%H:%M)$BLUE]\
PS2='> '
PS4='+ '

Feel free to copy into your .bashrc to have a colored prompt showing the current git branch if you are in a git repository.

2 Responses to Bash-Prompt for Git

  1. Sven says:

    Please provide an example of the result as screenshot.

  2. Fabian Buch Fabian Buch says:

    I updated the post and added a screenshot.

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.