If you’re working a lot with remote sessions like I do, you inevitably type a command in the wrong window… Most of the time it’s something harmless like an ls or an cd command, but if you’re trying to clean stuff up with an rm command things can get bad.
The easiest way to differentiate between local and remote sessions or different remote sessions is changing the background-color. When switching terminal, you immediately see/know where you are, without looking at the prompt or the window-title. So how do we implement this in the standard OSX Leopard Terminal.app ?
I like the terminal in OSX Leopard a lot but it doesn’t have support for some simple things like opening themed tabs or use the bookmark function like in iTerm. Because I prefer Terminal over iTerm, I tried hacking some scripts together
First I pick a theme I’d like to use on a daily basis from the Preferences - Settings window. In my case it’s "IR Black". Then I select the theme and duplicate it by pressing the small "cog" icon and selecting "Duplicate Settings". Rename the duplicated theme to something useful; I’m using one to connect to a server named "Pentagon", so I name it this way. Note that the duplicated theme automatically gets the Default theme being used when pressing ⌘T. You can select another theme and then click the "Default" button to set the original "IR Black" as default again.
Select the newly created "Pentagon" theme, go to the "window" tab and press the "Background Color" selector. Pick a color of your liking here. Because I like a darker background, I choose a very subtle tint of red in my black; just enough to notice it when in the terminal.
Right now we can manually open a new terminal window by going into the "Shell" "New Tab" menu and select the "Pentagon" theme there. If you like you can tweak the background color with the theme selected to see the changes immediately applied to your terminal screen.
Right now you have a different background-color, so you can start an ssh connection with the pentagon server, but I don’t like to use the mouse first and then start the ssh session manually. While looking around I came across a modification of Marc Liyanage’s "open terminal here" plugin, by Geoff using an applescript by Jacob Rus to open the menus and submenus from OSX apps programmatically.
I’ve mixed-and-matched the scripts and the ttterm (Themed Tab Terminal) script is the result. For the script to work, you need to enable "Access for assistive devices" on the "Universal Access" screen in "System Preferences". If this script is placed in your path, it can be called in two ways:
1) Opens a new tab with the selected [themename]
2) Opens a new tab with the selected [themename] and runs the [command] in the new terminal.
ttterm [themename] [command]
So if I want an ssh connection with pentagon, I can call:
ttterm Pentagon ssh max@pentagon
This is still quite long, so I add an alias to my .bashrc file and off we go.