Bash prompt (SVN branch + more root emphasis)

I rarely have the need to change my command prompt, but recently I stumbled across somebody displaying the GIT revision tag for the current directory along with some other information.

So my prompt script below includes the current SVN revision, additional tags can be added fairly easily at the expense of another couple of commands per line...

I've also added additional emphasis on the root user, showing bold red user@host and hash prompt.

This is based on the standard Gentoo PS1 prompt.

prompt_command() {
	local RS="\[\033[0m\]"
	local HC="\[\033[1m\]"
	local FRED="\[\033[31m\]"
	local FBRED="\[\033[01;31m\]"
	local FGREEN="\[\033[32m\]"
	local FBLUE="\[\033[01;34m\]"

	SVNBRANCH=`svn info 2>/dev/null | grep Revision: | cut -f 2 -d " "`
	if [ -n "$SVNBRANCH" ]; then
		BRANCH=" svn:$SVNBRANCH";
	else
		BRANCH="";
	fi

	AC="$FGREEN"
	if [ "$EUID" = "0" ]; then
		AC="$FBRED"
	fi

	ASHELL="$FGBREEN $"
	if [ "$EUID" = "0" ]; then
		ASHELL="$FBRED#"
	fi

	TITLEBAR="\e]2;\u@\h:\w $BRANCH\a"
	PS1="$TITLEBAR$RS$HC[$RS$AC\u@\h\$RS$FBLUE \w$RS$HC]$RS$BRANCH $ASHELL\[\033[00m\] "
}

PROMPT_COMMAND=prompt_command
export -f prompt_command
export PS1 PROMPT_COMMAND 

Leave a Reply



About

Harry is a professional developer and sysadmin from London, UK.

He's an atheist, employed at PixelMags LLC, a socialist and has a pragmatic outlook on life, love and religion.

Bookmarks

I'm constantly finding interesting stuff, here are some of the things I've bookmarked recently:

HarryR on Faves.com