Of course you can look at the hostname output but if you switch between numerous hosts all day you will have a fair chance you’ll enter a “sudo shutdown -r now” and have a “SH*T &^$*%)*()_(*&**%$” moment.
So in order bring some piece of mind and prevent myself for falling into the same trap (yes yes, I’ve been there as well.) I modify the shell prompt. This is easily doable with some ANSI escape codes:
I use 3 systems primarily and as such each of them has a different colour. Green for Dev, amber for Test and red for my production system. Since my home folder comes from an NFS share I only need to create a single block in the .bashrc file which checks for the hostname and the promptstring is automatically adjusted when logging in. Very handy:
if [[ $HOSTNAME == “dev_host” ]];then
export PS1=”\[\033[1;32m\][\$(date +%H%M)][\u@\h:\w]$\[\033[0m\] “
elif [[ $HOSTNAME == “test_host” ]];then
export PS1=”\[\033[1;33m\][\$(date +%H%M)][\u@\h:\w]$\[\033[0m\] “
elif [[ $HOSTNAME == “prod_host” ]];then
export PS1=”\[\033[0;31m\][\$(date +%H%M)][\u@\h:\w]$\[\033[0m\] “
else
export PS1=”\[\033[1;32m\][\$(date +%H%M)][\u@\h:\w]$\[\033[0m\] “
fi
The last line just makes sure all other hosts get a default “blue-ish” color including my own PC so that prevents me from having these mind-spins why the SQL return values don’t match. 🙂
Of course you can also use different backgrounds etc but I like to have a dark/black background, its easier on the eyes.
Cheers,
Erwin