Bash prompt history issue

拥有回忆 提交于 2019-12-03 09:15:29

问题


This is a weird one that I haven't been able to find a good answer with Google (of course there's always the possibility that I just fail at that). On my bash prompt, if I color a part of the prompt, when I hit 'up' to go to a previous command, I can't go to the start of the line after it's past a certain amount of characters (specifically 31).

My current bash prompt is this: (colors are defined earlier in my .bashrc)

PS1="[\u@$cyan\h$NC \w] "

But if I change it to this:

PS1="[\u@\h \w] "

It no longer prevents me from going to the beginning of the line.

The odd part, is visually, when I hit home to go to the beginning of the line (or use the arrow keys) it stops 11 characters in to the string, but if I edit it from there, it does edit starting at the beginning of the line.

Does anyone know why this might be happening? I would like to use colors in my prompt as I do server administration and the colors is how I differentiate my boxes at a glance.


回答1:


Non-printing sequences such as color codes must be surrounded by \[ and \] so their lengths are not counted as part of the length of the prompt.



来源:https://stackoverflow.com/questions/10594786/bash-prompt-history-issue

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