开发者

Bash line wrapping and history scrolling

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 corre开发者_高级运维ctly out of the box (this is at my workplace).

regards,

JP


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).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜