Change terminal colors to visually know whether the prompt is local or remote.
First World problem
I tend to have (lots of) terminals open in my desktop, and sometimes I do not know whether the terminal is inside a remote server (meaning I have SSH-ed into), or it’s just my local machine. Furthermore, I would like to differentiate between
- Local machine (Mac OS X)
- Work servers (tend to be Linux)
- Personal server(s)
Consider the terminal below. How do I know whether
top is listing the local processes or my remote processes? I can, of course, look at the window title which normally gives some clues about which computer I am logged into (no
ubuntu in this case). But it requires a level of attention that I usually don’t have. I have deleted the wrong files, or killed the wrong process because of this.
My solution: whenever I log into a server, change the color (theme really) of the terminal. How do we do this? See below.
Changing Terminal Colors
In order to change the color of the Terminal, we can use an OS script once we have SSH-ed into the server. Or we can wrap SSH so that we change the color, login into the server, and change the color back. The following
Note that the last two lines of the script will only run once I have logged out of the remote machine. On ocassion I have had weird broken connections that break this scheme, but for the most part it works very well.
Since I do not want to learn a new command I alias the
ssh command to
Stick it into your
.profile and you are set. Next time you open a terminal and
ssh somewhere the terminal will turn from the default theme (“Homebrew” in my case) to the remote theme (“Ocean” in my case).