3

Can I do this?

OMG, I looked for hours, and every article I find tells me how to colorize the output of ls. Or colorize my prompt. I really really really don't want that.

I want to colorize the text. The default text in the terminal window.

I know I can do this from Terminal Preferences. But that applies to EVERY terminal window that's open, which I don't want.

As the subject says, I'd like to have three different terminal windows with three different default colors for text in them. How can I do that?

In Windows cmd.exe, I could run a command from the prompt: color 0xA 0xG (something like that) and it would re-colorize the basic text and background. rather that pointy-clicky inspector themes menus and all that... can I do something like this from the MacOS Terminal prompt?

7

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

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.

You must log in to answer this question.

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