Interaction between profiles of Terminal.app and environment variables

bashcolorenvironment-variablesitermterminal

I wonder if and how it is possible to set shell environment variables based on the Terminal.app profile.

More specifically, I would like to use a coloured prompt in Terminal.app or iTerm2.app in Mac OS, but I would like to set the prompt colours (with PS1 variable) based on the selected profile of Terminal.app. Is it possible to define environment variables as a part of the profile in Terminal.app? Are there any workarounds for Terminal.app or for other terminal applications (for any operating systems) to define the prompt format and colors based on the selected "profile"?

Best Answer

You can run shell command on profile launch. You can find it in:

Preferences -> Profile -> Selected Profile -> Shell -> Run command.

You can have separate files with PS1 variable and source them using this "Run command" option.

enter image description here