I searched and found this article http://www.ibm.com/developerworks/linux/library/l-tip-prompt/ . And I came to the conclusion that this is a problem about coloring in bash and line wrapping.
Root cause is, coloring codes are not enclosed in bracket \[...\] which means Bash(or Xterm, I'm not sure) have to count the coloring code characters as characters on the line and does line-wrapping using the count. And this messes up the whole line.
Solution:
- find every file that setting the color for bash prompt. Possible files are:
- ~/.bashrc <<< I found my prompt setting in here
- /etc/profile
- /etc/profile.d/*.sh
- /etc/bash.bashrc
- To check if your prompt setting in either of the files, look for the word "PS1"
- If there is any color code such as
### Prompt ((UID)) && User="\e[1;32m" || User="\e[1;31m" PS1="$User\u\e[0;34m@\h\e[0;37m\w$User\\$\e[m "
Enclose every color codes with \[...\], so they become
### Prompt ((UID)) && User="\[\e[1;32m\]" || User="\[\e[1;31m\]" PS1="$User\u\[\e[0;34m\]@\h\[\e[0;37m\]\w$User\\$\[\e[m\] "
- Save the file and you're done.
Next time you open your bash prompt again, it'll be problem-free :)
Wow...thanks! This has been driving me crazy for over a year.
ReplyDelete