views:

345

answers:

3

I admit that I use a somewhat long-winded bash prompt:

--(username)-(Wed April 01|12:00:00)--(~ $

Recently, I got the bright idea to change it so that depending on the exit value from the previous command, if success, the interior elements of the ()'s would be green, and if failure, they would be red. I got it working for the most part (some odd exit statuses will change the color to something else, but I'm ok with it), but when typing a command which is more than one line, and causes the terminal to scroll, the prompt disappears! My prompt worked fine when there was no color, so I'm guessing it is related to my color escaping, and particularly my unclosed ['s, but I can't pin it down.

#.profile
export PS1='--(\e[$((32-${?}))m\u\e[0m)-(\e[$((32-${?}))m\d\e[0m|\e[$((32-${?}))m\T\e[0m)--(\e[$((32-${?}))m\w\e[0m \$ '

Thanks in advance!

+3  A: 

It sounds like this should solve your problem.

This seems to work for me*:

export PS1='--(\[\e[$((32-${?}))m\]\u\[\e[0m\])-(\[\e[$((32-${?}))m\]\d\[\e[0m\]|\[\e[$((32-${?}))m\]\T\[\e[0m\])--(\[\e[$((32-${?}))m\]\w\[\e[0m\] \$ '

* well, really export PS1='\u@\h:\w\$ ' works for me

Chas. Owens
Chas, just looking at that prompt makes my eyes red. Thank you for your help, sir! Yours was the only solution that seemed to work completely.
BigDave
+2  A: 
lhunath
+1  A: 

You just seem to be missing the start and end brackets around your escapes (before the first '\e' and after the last 'm'):

PS1='--(\[\e[$((32-${?}))m\u\e[0m)-(\e[$((32-${?}))m\d\e[0m|\e[$((32-${?}))m\T\e[0m)--(\e[$((32-${?}))m\w\e[0m\] \$ '

As mentioned, the PS1 var does not need to be exported: only your shell needs to see it.

glenn jackman