I need to have different color schemes for each of the two terminal types I use. I can set it in the .bash_profile as mentioned here. But how can I tell it to differ depending whether its a iTerm2 or default terminal instance?
2 Answers
There is an environment variable set by iTerm and by Terminal as the following:
for Terminal:
TERM_PROGRAM=Apple_Terminal
for iTerm:
TERM_PROGRAM=iTerm.app
You should see this variable by typing in env
from the command line.
So - using this variable, you can put a condition in your .bash_profile
to select the proper coloring.
-
2
Environment variables are not reliable as they don't necessarily get passed through SSH.
https://groups.google.com/g/iterm2-discuss/c/MpOWDIn6QTs
Here's a script that can detect if you're using iTerm: https://iterm2.com/utilities/it2check
-
This depends on how you use ssh. You can also pass environment variables via ssh. It may be a bit inconvenient, but if you encapsule your ssh invocation into a script, it can be made easy to use. Commented Mar 22, 2023 at 11:18
-
yes, that's why I said "they don't necessarily get passed through SSH". If someone creates a script that detects the terminal with those variables, and I use that script on a server but I have not ensured that the variables are passed to it, then their script fails to detect iTerm. Usually we want scripts to just work, and not rely on the user to bend over backwards to change their habits to accommodate the script. Commented Mar 22, 2023 at 17:20