Macos – iTerm 2 profiles

itermmacos

I have recently switched over to iTerm2 and love it. I am wondering though if there is a way to use profiles to correspond to what environment/specific machine you are on.

Say if I am doing tasks in one window on my mac the profile is displayed as default, but if I ssh into a machine (lets say dev0), the profile on iTerm will update to profile dev0. Once I've finished with dev0 and call exit, the profile will switch to default again.

I realize one work around is to open up a specific profile whenever I want to ssh into another machine and have a way to distinguish, but if the connection is closed it requires you to notice based off text rather than say the background of the window.

Is this possible? If not how can this feature be added, and is there a way I can contribute?

Best Answer

iTerm2 supports a custom escape code that changes the profile on the fly. Put it in your .bashrc or .bash_profile.

<esc>]50;SetProfile=X^G

where X is the profile. For instance, to change the profile to one called "Foo", us this shell script:

#!/bin/bash
echo -e "\033]50;SetProfile=Foo\a"

To change it back when you log out, put code to change the profile back to default in ~/.bash_logout.

Related Topic