Here is one that a friend of mine and I have been working on. It gives a gray dashed line when you are a normal user, then if you are running commands as a root user, it changes to red for both the dashed line and the text.

In your .bashrc
file, add the following code to the bottom of the file:
if [ -f "$HOME/.bash_ps1" ]; then
. "$HOME/.bash_ps1"
fi
EDIT: Also, add it to the bottom of the /root/.bashrc
as well. This is for if you switch to the root
user by issuing the command sudo su -
. (The rest of the edit is continued below code)
Then copy and paste the rest of this code to a new file called /home/<username>/.bash_ps1
# Fill with minuses
# (this is recalculated every time the prompt is shown in function prompt_command):
fill="--- "
reset_style='\[\033[00m\]'
# determine if root or not
a=$(id|awk -F\( '{print $1}')
if [ "$a" = "uid=0" ]
then
# for root
status_style=$reset_style'\[\033[1;31m\]' # bold red; use 0;37m for lighter color
command_style=$reset_style'\[\033[1;31m\]' # bold red
else
# for other users
status_style=$reset_style'\[\033[0;90m\]' # gray color; use 0;37m for lighter color
command_style=$reset_style'\[\033[1;29m\]' # bold black
fi
prompt_style=$reset_style
# Prompt variable:
PS1="$status_style"'$fill $(date +"%m/%d/%y ")\t\n'"$prompt_style"'${debian_chroot:+($debian_chroot)}\u@\h:\w\$'"$command_style "
# Reset color for command output
# (this one is invoked every time before a command is executed):
trap 'echo -ne "\033[00m"' DEBUG
function prompt_command {
# create a $fill of all screen width minus the time string and a space:
let fillsize=${COLUMNS}-18
fill=""
while [ "$fillsize" -gt "0" ]
do
fill="-${fill}" # fill with underscores to work on
let fillsize=${fillsize}-1
done
# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
bname=$(basename "${PWD/$HOME/~}")
echo -ne "\033]0;${bname}: ${USER}@${HOSTNAME}: ${PWD/$HOME/~}\007"
;;
*)
;;
esac
}
PROMPT_COMMAND=prompt_command
EDIT (Part 2): Now create a link to the .bash_ps1
in your /root
folder
sudo -s
cd /root
ln -s /home/<username>/.bash_ps1
You can change any of the above code to fit your needs. This is one that I use actually at work so that I know if I am typing in commands as a root
user that could be potentially dangerous. Plus, the time stamp appears just above each line you type, making it a little easier if you scroll back to see when you typed in that command.
Hopefully this helps!
PS1="\[\033[33m\]\@ \w \$ \[\033[0m\]"
. – DK Bose Sep 20 '15 at 17:17