»
January 28, 2010
»

Mercurial Branch in Bash Prompt

Git has nice bash function for showing current branch and status in bash prompt. Here is the branch only version for Mercurial:

hg_branch.png

__hg_ps1 ()
{
  if [ "$(hg root 2> /dev/null)" ]; then
    printf "$1" "$(hg branch)"
  fi
}

export PS1='\u:\w$(__hg_ps1 " (%s)\$ '

and PS1 version with colors:

export PS1='\u:\w$(__hg_ps1 " \[\033[1;31m\](%s)\[\033[0m\]")\$ '
 
Internet Explorer 6
Are you serious?