Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bash prompt history issue

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.

like image 256
Jossie B Avatar asked May 15 '12 05:05

Jossie B


People also ask

How do I turn off Bash history?

How to permanently disable bash history using set command. Again add set +o history to the end of to a new /etc/profile. d/disable. history.

How do I see entire Bash history?

The command is simply called history, but can also be accessed by looking at your . bash_history in your home folder. By default, the history command will show you the last five hundred commands you have entered.

Does Bash Support command history?

The Bash version of history allows for reverse searches, quick recall, rewriting history, and more. Display or manipulate the history list.


1 Answers

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.

like image 200
Dennis Williamson Avatar answered Oct 23 '22 10:10

Dennis Williamson