views:

586

answers:

4

I've done something to break my Bash Shell Prompt in OS X (10.5.7) Terminal.

This is the PS1 that I had configured:

PS1='\[\e[1;32m\]\h\[\e[0m\]:\[\e[1;34m\]\w\[\e[0m\]\$ '

As far as I can tell I have the color commands escaping correctly. However when I scroll up and down in my command history I often get line wrapping issues if the historic commands wrap onto multiple lines.

I simplified my prompts to the following:

PS1='\[\e[1m\]\h:\w\$ \[\e[0m\]'
PS2='> '

And I still see something like:

localhost:~/Library/Application Support/Firefox/Profiles/knpmxpup.Defau
lt/extensions/{1A2D0EC4-75F5-4c91-89C4-3656F6E44B68}$ expocd \{1A2D0EC4-7
5F5-4c91-89C4-3656F6E                                           export PS1="\[
\e[1;32m\]\h\[\e[0m\]:                                          cd Library/Appl
ication\ Support/

I've also tried \033 instead of \e. I just included PS2 up there for information, I haven't changed that from the install default. If I completely remove the color codes then everything works fine, any ideas?

A: 

Line wrapping issues in Bash are nothing new. Consult the Mailinglist, maybe there's yet another bug regarding this.

You can't do much more than tagging unprintable characters, the rest must be done by the prompting code.

TheBonsai
Thanks, I just wanted to confirm that I had escaped things correctly.
Rob
A: 

It seems that you have correctly escaped and enclosed sequences.

A workaround I use anyway it it to add a '\n' at the end. I find it clearer and lessen any problem with wrapping issues. The exact end of my PS1 is :

'\n\[\033[0;30m\]$\[\033[0m\]

An excellent howto you probably know :

Bash prompt howto

neuro
+1  A: 

This stackoverflow thread seems relevant. As someone noted in that thread, the Bash FAQ at mywiki.wooledge.org discusses how to properly quote color codes in Bash prompts (FAQ 53), and the proper invocation of terminal colors (FAQ 37). Sorry, I don't enough reputation points to post the links directly (currently I'm limited to one link per reply).

willdye
Using tput to generate my color codes as described in this FAQ:http://mywiki.wooledge.org/BashFAQ/037And my prompt scrolls much better. However I am also on a new version of OS X so I am not sure which may have fixed this.
Rob
A: 

I am now using this PS1 with good effect:


green=$(tput setaf 2)
blue=$(tput setaf 4)
bold=$(tput bold)
reset=$(tput sgr0)
PS1='\[$green$bold\]\h\[$reset\]:\[$blue$bold\]\w\[$reset\]\$ '

Scrolling through my command history appears to handle line wraps now. However in the meantime since this question was asked I have also updated my OS X to 10.6.3

Rob