Thursday, October 2, 2008

Lost in a sea of terminals

Usually I enjoy my screen being covered with a variety of terminals across multiple servers. But on occasion, I type utterly the wrong thing, in utterly the wrong place, and calamity ensues.

So to provide a slight buffer against this, I made a change in my bash prompt. It clues me in if I am on a remote server, a non-personal machine if you will, on which I need to exercise more caution before beating the enter key:
Just something noticeable, but not overly intrusive. Won't stop idiocy, of course, but it can't hurt.

To make it work:

# Prompt with easier to read coloring. Define and check for safe boxes:
declare -a LOCALBOXES[0]="MyBox1" LOCALBOXES[1]="MyBox2"
CURRENTBOX=`hostname`
for box in $LOCALBOXES
do
if [[ $CURRENTBOX = $box ]] ; then
PS1="\[\033[0;31m\][\T]\[\033[0;36m\]\u@\[\033[1;33m\]\H \[\033[1;34m\]\w: \[\033[0m\]"
else
PS1="\[\033[1;36m\]**REMOTE**\[\033[0;31m\][\T]\[\033[0;36m\]\u@\[\033[1;33m\]\H \[\033[1;34m\]\w: \[\033[0m\]"
fi
done

2 Comments:

Blogger mray said...

I like to use a little color to warn myself when I'm root:


PS1="\h:\$(date +%H:%M):\w
\[\033[1;41m\]\[\033[1;37m\]ROOT\033[0m # "

October 2, 2008 at 3:30 PM  
Blogger by Immortal Curiosity said...

That sounds like a good idea, but I try never to have to work as root on a server:-)

October 2, 2008 at 9:36 PM  

Post a Comment

Subscribe to Post Comments [Atom]

<< Home