Automatic profile switching in iTerm2

Distinguish projects and environments with an easy hack

Terminals are great. They allow you to run any command in any folder on any machine unrestricted. But with great power comes great responsibility. Quite often you are just one-command-away from running the wrong command in the wrong project (on or the wrong server) which can erase all your changes or even destroy the production.

The problem is that usually, all our terminals are the same colour (usually black). It’s hard to tell at a glance if you are in the right project directory or even ssh-ed to the right machine. Have you heard all these stories that someone cleared the production thinking that they are on the staging environment?

Fortunately, the iTerm 2 has really nice feature which allows you to change the iTerm Profile based on your current path or the machine you are running on (when connected remotely). You can also set the badges (big texts in the background on the following screenshot) to have more context on where you are now.

To set it up, you would first need to install Shell Integration extension for iTerm2.

You will get an option to install only Shell Integration or all Utilities (for viewing images in the console and more). Only the first one is required for the trick to work.