Bash prompt line wrapping issue

丶灬走出姿态 提交于 2019-11-30 23:31:02

问题


Newbie question, I recently changed my PS1 into this:

RESET="\[\017\]"
NORMAL="\[\033[0m\]"
YELLOW="\[\033[0;33m\]"
CYAN="\[\033[0;36m\]"

export PS1="\[$RESET\]\u@\h:\[$CYAN\]\w\[$YELLOW\]\$(__git_ps1)\[$NORMAL\] \$ "

But now I get a line wrapping error. I created a gif to explain the problem:

Any ideas what might be wrong?


回答1:


I think you're double-quoting your escape codes with [ and ]. Try this one:

export PS1="$RESET\u@\h:$CYAN\w$YELLOW\$(__git_ps1)$NORMAL \$ "



回答2:


The wrapping error occurs whenever a non-printing character is not escaped (such as the escape codes that change the prompt color). It also occurs when the locale is set to something that does not understand unicode characters and the prompt includes them. An example would be non-breaking spaces. When the locale is "C" and there are unicode characters in the prompt, the shell thinks more characters are being printed than truly are, and the prompt wraps around prematurely.



来源:https://stackoverflow.com/questions/18559417/bash-prompt-line-wrapping-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!