Playing with iTerm's tabs

· Read in about 2 min · (283 Words)
ruby iterm mac

iTerm2 is the best terminal emulator currently available on Mac OSX, I use it daily for development and sysadmin work and rarely regret running unstable builds.

One of my favoute features in iTerm is its tabs. As you’d probably expect, ⌘T opens a tag – with a new shell – and you can drag and detach them just like you would in other applications.

Earlier today I was reading its documentation and I came across this page about the proprietary escape codes it supports.

Escape codes are the things you’ve probably used in the past when you set your term’s title or colourised your prompt, but you may not have realised that different terminal emulators have their own sets of codes. There’s plenty available to read online, I’ll let you search if you’re interested :)

iTerm lets you clear history, add to the clipboard, tweak themes and change the colour of tabs.

Anyway, I thought it might be fun to programatically change the colour of iTerm tabs, so hacked up a quick ruby script, using the color-tools gem to parse CSS colour names.

Here it is:

Run it like this:

iterm red

or in a for loop … and here’s the resulting awesomeness!

GIF

Good fun, and potentially useful if you use colourcoded tabs to keep track of multiple SSH sessions.

In fact, the best way I’ve found of using this trick is to put something like this in your ~/.ssh/config file:

PermitLocalCommand yes

Host beefy beefy.local
  LocalCommand ~/bin/iterm blue

Host shrimp shrimp
  LocalCommand ~/bin/iterm red

This will change the tab to a specific colour after you’ve logged in to a configured server. Cool hey?! You can change it back manually using iterm reset.

Comments