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"?


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

  • Can i use this feature to just set an environment variable directly? What commands are allowed? I tried to put there export TERMINAL_APP_PROFILE='My Green Theme', but got "[Command not found: export]".
    – Alexey
    Aug 18 '16 at 14:10
  • It works for me, but You have to check Run inside shell. I got there: export TERMINAL_PROFILE="My Profile" and I can access this variable inside this profile. Aug 18 '16 at 14:23
  • Thanks. Yes, the problem was that i didn't check "Run inside shell". Is there no way to run it silently, without showing it in terminal window?
    – Alexey
    Aug 18 '16 at 14:49
  • I don't know about running it silently, but if you execute a "clear" command in there after the export you'll only see a flash of the text and then you'll just see a prompt: "export TERM_PROFILE=solarized_dark; clear" Aug 21 '17 at 0:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .