4

I am having trouble with my bash prompt and line wrapping behaviour. If I use a static prompt

export PS1="test$ ";   ### Works perfectly

I can type long lines on the prompt and they wrap fine. Scroll up/down in history also work fine. On using dynamic prompt like:

export PS1="\u@\h(\W)$ ";    ### Long lines don't wrap at all

long lines got scrambled. Found a fix that made long lines wrap correctly. (http://hintsforums.macworld.com/showthread.php?t=17068).

export PS1="\[\u@\h(\W)$ \]";  ### Long  lines wrap while typing, but not while scrolling up/down through previous commands

However, when going up/down the prompt history, the lines do not wrap. I dont know how to explain the behaviour in words, but I will try - when I go up (up arrow key), half the last command is eaten up and cursor ends up somewhere in between where the line would have wrapped.

What is the solution for this?

I remember that on many linux distributions dynamic prompts work correctly out of the box (this is at my workplace).

regards,

JP

  • By the way - in the third case PS1="\\[\u@\h(\W)$ \\]", I dont even know the right term for the behaviour - whether it is wrapping while scrolling and I dont want it to wrap or its not wrapping and I want it to wrap. I am confused with the crazy display though! –  Nov 19 '10 at 06:13
  • 2
    What terminal software? PuTTY, gnome-terminal, xterm, Terminal.app? The second example is correct and should work. The `\[\]` in the third example is used to wrap non-printing sequences like color codes. – Dennis Williamson Nov 19 '10 at 15:23
  • Terminal software is Putty. Thanks for the suggestion, I will try. –  Nov 21 '10 at 12:08

1 Answers1

1

This issue is probably not about the prompt itself, but more likely about the terminal emulator behaving properly.

I use this bash prompt:

export PS1="\[\e[1;34m\]\u@\h:\W \t (\j) <\!>\n\$\[\e[0;00m\]"

which actually displays across two lines, looking exactly like this:

aks@anywhere:sh 01:43:27 (1) <1017>
$ env | grep PS
PS1=\[\e[1;34m\]\u@\h:\W \t (\j) <\!>\n\$\[\e[0;00m\]

and it works perfectly fine with history scrolling, using either CTRL-N, CTRL-P, or the arrow keys.

I am using xterm-color in Terminal.app (on a MacBookPro).

aks
  • 2,328
  • 1
  • 16
  • 15
  • Bugger, I have been living with this problem for years, all because I didn't correctly end my prompt by resetting the colours in this way. Thanks! – Robert Mark Bram Mar 06 '14 at 05:25