How to have different colors in each Terminal window

Solution 1:

I may not be understanding the question fully, since you change the color settings per-tab/window contrary to your question, but here is how to do what I think you want.

  1. Go to Terminal menu > Preferences.
  2. Click on the Settings tab.
  3. Click on the gear icon at the bottom left and choose Duplicate Settings.
  4. Enter a name for your settings.

    Preferences window, Settings tab

  5. Make any changes you want to font colors.

  6. Repeat steps 3 through 6 until you have as many sets of colors as you want.
  7. Close the Preferences window.
  8. Open as many tabs as you want (3, it sounds like).
  9. Right-click on the first and choose Inspect Tab.

    Terminal window with tab Inspector open

  10. Select your desired Settings pre-set from the list. (The ones you created will be down towards the bottom.)

  11. Close the Inspector window.
  12. Repeat steps 9 through 11 until you have customized each tab.

That should be it. If you want Terminal to always open like this, with these three tabs and their associated color settings:

  1. Go to Window menu > Save Windows as Group.
  2. Enter a name.
  3. Click Save.
  4. Go to Terminal menu > Preferences.
  5. Click on the Startup tab.
  6. Next to "On startup, open:" choose the radio button for "Window group:" and select the name of the group you created in step 2.

    Preferences window, Startup tab

Solution 2:

One approach is to use an escape sequence in your prompt to colourize the text. If you don't end the prompt with the reset sequence, the colour will persist into the text you type and the output of commands (except when the output uses colour codes itself).

The Mac terminal supports the full 256-colour xterm escape codes (you can find a full description of them at http://invisible-island.net/xterm/ctlseqs/ctlseqs.html). You just need to select a colour for each session and set $PS1 to an appropriate sequence, probably in your .bashrc file.

This is a crude version that simply picks a random colour for each session:

colour=0x$(xxd -p -l 1 /dev/urandom)      # Random number from 0x00 to 0xff
(( colour=colour ))                       # Convert to decimal
export PS1='\[\e[38;5;'$colour'm\]\w $ '  # Set the foreground colour

You might want to do something more sophisticated to avoid picking colours that are hard to see against your background colour.