Question

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.

Était-ce utile?

La solution

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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top