Bash 换行和历史滚动
我的 bash 提示符和换行行为遇到问题。如果我使用静态提示符,
export PS1="test$ "; ### Works perfectly
我可以在提示符上键入长行,并且它们可以很好地换行。在历史记录中向上/向下滚动也可以正常工作。 在使用动态提示时,例如:
export PS1="\u@\h(\W)$ "; ### Long lines don't wrap at all
长线变得混乱。找到了使长行正确换行的修复程序。 (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
但是,当向上/向下浏览提示历史记录时,行不会换行。我不知道如何用语言解释这种行为,但我会尝试 - 当我向上(向上箭头键)时,最后一个命令的一半被吃掉,光标最终位于换行符之间的某个位置。
对此有什么解决办法吗?
我记得在许多 Linux 发行版上,动态提示可以开箱即用地正常工作(这是在我的工作场所)。
问候,
太平绅士
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
此问题可能与提示本身无关,而更可能与终端仿真器的正常行为有关。
我使用这个 bash 提示符:
它实际上跨两行显示,看起来完全像这样:
使用 CTRL-N、CTRL-P 或箭头键,它与历史滚动完美配合。
我在 Terminal.app(在 MacBookPro 上)中使用 xterm-color。
This issue is probably not about the prompt itself, but more likely about the terminal emulator behaving properly.
I use this bash prompt:
which actually displays across two lines, looking exactly like this:
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).