Bash Prompt Wrapping Issue

旧街凉风 提交于 2019-12-25 03:31:15

问题


I seem to be running into a situation with my custom Bash Prompt, very similar to this one here:

Bash prompt line wrapping issue

I'm thinking escaping might be my issue (as mentioned in the url above) I've tried moving things around and removing my brackets, but all that does is mess up my bash prompt. Is someone able to lend a hand with this:

"What! \[\e[1;33m\]\w\[\e[m\]\[\e[37m\]\$(parse_git_branch)\[\033[00m\] \e[m\]$ "

回答1:


All non-printing segments in the must be surrounded by \[...\] and all printing segments must not be surrounded by those.

You have at least one space inside \[...\] near the end.

You also have a large number of unclosed \[ (count your matched pairs).

Using variables for the color codes themselves (as in the linked question) will simplify seeing where the escapes need to go in the prompt itself. (Though the linked question puts the prompt escapes in the variables also which complicates seeing what's going on a bit to my mind.)



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

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