Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Is there a way for the command line and the output to be in different colors? For example, I've been playing with the PS1 value so my prompt is in red, but I'd like to have the command line in green and the output in white (ex: if I type "ls", that's in green, and then the file list is in white).

share|improve this question
add comment

3 Answers

You need to have the shell, or a program, emit the appropriate escape sequence to change the colours after you press enter.

The bash shell used by current OS X doesn't have an obvious facility for doing this.

share|improve this answer
    
Is there any way to alias a return key to be "color escape sequence + return"? –  punkkat Jun 27 '12 at 20:38
add comment

At the end of your PS1 have an escape sequence set the color of your input. For example,

PS1="\h \w$ \e[0;32m"

(all that matters is the \e[0;32m part at the end (which could be any color), the rest is up to you)

To set the output color differently, you need to "trap" the "DEBUG" signal and call some function. Here's what I have

debug()
{
  echo -n $'\e[0m';
}
trap debug DEBUG

It's not complicated, it just ensures that whenever you enter a command (which causes the DEBUG signal) the debug function is called.

So just copy those lines into your .bash_profile or .bashrc or whatever you're using, and change the '\e[0m' to whatever color you like.

share|improve this answer
add comment

You could bind another key to send the escape sequence and a return.

  1. In Terminal's preferences, click on the Settings pane, then the Keyboard tab.
  2. Click the plus button.
  3. Choose a modifier and key. Set the action to send string to shell and the string to \033[m\015. Click OK.

You'll have to get used to using that keyboard shortcut instead of return…although there's probably an app that will let you the system treat return in Terminal as that alternate shortcut.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.