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.

I get different behaviors in terminal with the same prompt definition in Snow Leopard and Lion.

On my Snow Leopard system, I define my terminal prompt in .profile as follows:

export PS1='\[\e[32;1m\]\w\$\[\e[0m\] '

This creates a green-on-black prompt, with the output from normal commands being white-on-black by default. (For example, if I type man I get the output What manual page do you want? in white-on-black.)

On my Lion system, with the same .profile, I get the same green-on-black prompt but text color no longer switched back to white-on-black. (If I type man I get the output What manual page do you want? in the same green-on-black as the prompt.)

Why does Lion's terminal behave differently -- and how do I get it to change text back to white-on-black?

share|improve this question

migrated from stackoverflow.com Feb 24 '12 at 1:25

This question came from our site for professional and enthusiast programmers.

    
I cannot reproduce the problem on 10.7.3, Terminal 2.2.2. I pasted and executed your export command. The prompt is green text, but all the other text is the default terminal text color. You might try your PS1 value with xterm or some other terminal program for comparison. Also, verify your PS1 value by printing it with echo "$PS1" | cat -v (the cat -v will ensure it displays control characters). –  Chris Page Feb 26 '12 at 12:53
    
Like Chris, I could not reproduce that on my Snow Leopard and Lion systems. I suggest you set PS1 from the command prompt and see if the problem persist. If it fixes your problem, that means something in your start up files (.profile, .bash_profile, ...) messes it up. –  Hai Vu Feb 28 '12 at 21:12
    
Thanks guys. I finally came back to this and figured it out. The problem all along was that my Terminal preferences had the basic text color set to bright green! –  Ghopper21 Jun 15 '12 at 20:40
    
Please consider posting an answer to this question. –  Daniel Beck Jul 16 '13 at 5:10
add comment

2 Answers

A better (because its more portable across upgrades and different systems) way to handle the prompt settings is by using tput with terminfo codes to always get the proper codes for your term type. From the man page "uses the terminfo database to make the values of terminal-dependent capabilities and information available to the shell"

Here is an example from my .profile

red=$(tput setaf 1)
green=$(tput setaf 2)
blue=$(tput setaf 4)
reset=$(tput sgr0)
PS1="\[$red\]\u\[$reset\]@\[$green\]\h\[$reset\]:\[$blue\]\w\[$reset\]\$ "

from the terminfo man page the codes setaf is

   set_a_foreground             setaf       AF       Set foreground
                                                     color to #1, using
                                                     ANSI escape

See tput(1) and terminfo(5) for more of what you can do with that.

share|improve this answer
    
Is there a known case where ANSI escape codes broke due to a software update? –  Daniel Beck Jul 16 '13 at 5:10
    
I think the default term type changed to xterm-256color between Snow Leopard and Lion which I assume has a different terminfo db entry. This may be the source of the escape code differences, but I don't have a backup of my old terminfo from Snow Leopard to check –  numeric illustration Jul 16 '13 at 6:59
    
Thanks! This wasn't my issue but is a cool trick to know about! –  Ghopper21 Jul 16 '13 at 15:01
add comment
up vote 0 down vote accepted

Short answer is that as far as I can tell, there isn't a difference after all. The problem all along was that my Terminal preferences had the basic text color set to bright green!

share|improve this answer
    
Note: I'm adding this as the answer in response to the moderator request. –  Ghopper21 Jul 16 '13 at 15:01
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.