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?
A profile enables you to open a new command line window in a certain directory and run commands automatically. Let's make one! First, close all open command line windows in iTerm, and start with a new command line window. Next, you'll want to navigate to “Profiles” in the Menubar and click “Open Profiles…”
iTerm stores profiles in `~/Library/Saved Application State` which is not backed up by time machine.
iTerm2 allows you to divide a tab into many rectangular "panes", each of which is a different terminal session. The shortcuts cmd-d and cmd-shift-d divide an existing session vertically or horizontally, respectively. You can navigate among split panes with cmd-opt-arrow or cmd-[ and cmd-].
Go to iTerm2 -> Preferences -> General . Under the Preferences tab , Tick Load Preferences from a custom folder or a URL: and choose a folder and click on Save Now .
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.
for zsh users
lets say you have 2 profiles, one named mac (for your primary machine) and one for linux (your remote machine)
when entering the session, we need to tell zsh to load our profile
~/.zshrc
add echo -e "\033]50;SetProfile=linux\a"
source ~/.zshrc
when exiting the session, we need to tell zsh to switch back to our original profile
~/.zlogout
add the followingif [ "$SHLVL" = 1 ]; then echo -e "\033]50;SetProfile=mac\a" clear fi
now you can swap profiles with ease <3.
if you are using bash, i believe the steps are similar but you would instead modify ~/.bashrc
and ~/.bash_logout
demo
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With