Skip to content

Instantly share code, notes, and snippets.

@Pegolon
Created January 7, 2011 10:10
Show Gist options
  • Save Pegolon/769315 to your computer and use it in GitHub Desktop.
Save Pegolon/769315 to your computer and use it in GitHub Desktop.
Shows the current branch of a git or mercurial repository as the last part of your command line prompt
function parse_branch {
local BRANCH=$(git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/')
if [ -z "$BRANCH" ]
then
BRANCH=$(hg branch 2>/dev/null)
if [ -n "$BRANCH" ]
then
BRANCH="("$BRANCH")"
fi
fi
echo $BRANCH
}
function proml {
local BLACK="\[\033[0;30m\]"
local RED="\[\033[0;31m\]"
local BOLD_RED="\[\033[1;31m\]"
local GREEN="\[\033[0;32m\]"
local BOLD_GREEN="\[\033[1;32m\]"
local BROWN="\[\033[0;33m\]"
local YELLOW="\[\033[1;33m\]"
local BLUE="\[\033[0;34m\]"
local BOLD_BLUE="\[\033[1;34m\]"
local PURPLE="\[\033[0;35m\]"
local BOLD_PURPLE="\[\033[1;35m\]"
local CYAN="\[\033[0;36m\]"
local BOLD_CYAN="\[\033[1;36m\]"
local WHITE="\[\033[1;37m\]"
local BOLD_GRAY="\[\033[0;37m\]"
case $TERM in
xterm*)
TITLEBAR='\[\033]0;\u@\h:\w\007\]'
;;
*)
TITLEBAR=""
;;
esac
PS1="${TITLEBAR}\
$RED[$GREEN\u@\h:\w$BLUE\$(parse_branch)$RED]\
$BLUE\$ "
PS2='> '
PS4='+ '
}
proml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment