Adding ANSI color escape sequences to a bash prompt results in bad cursor position when recalling/editing commands
问题 If I set my command prompt like: export PS1='\033[0;33m[\u@\h \w]\$ \033[00m' The color of the prompt will be yellow and everything after the '$' character will be the default terminal color. This is what I expect. However, If I recall a command line and attempt to edit it, moving the cursor -- either UpArrow/Ctrl-A (set -o emacs) or ESC K (set -o vi) if the command line I'm trying to edit is long enough, the cursor is not positioned at the beginning of the command. Typing either Ctrl-A (set