Roachys Weblog

A digital notebook of technical experiences

Archive for February 25th, 2008

Changing the colour of the root prompt in a bash shell

with 2 comments

I’m terrible for forgetting to exit a root session after I’ve been performing administrative functions on my machine, so I looked for some way of reminding me, and found this simple solution:

Edit the /etc/bashrc file to include the following function….

function setprompt
{
local RED="[$(tput setaf 1)]"
local RESET="[$(tput sgr0)]"
if [ `id -u` = 0 ] # check if user is root
then
PS1="$RED[u@h:W]$RESET "
else
PS1="[u@h:W]$RESET "
fi
}
setprompt

This then changes the prompt colour to red (or any colour you like) when logged on as root…..

Red Shell Prompt

Written by Paul Morgan-Roach

February 25, 2008 at 11:13 am

Posted in Linux

Tagged with , , ,