Terminal prompt 'saving' certain commands on up-arrow
Solution 1:
You're not escaping the non-printing characters in your prompt. See this article, and use "\[
" and "\]
" around the colors, something like this (untested) for example...
PS1="\n\e[0:\[${color}\]m[\W]\n\e[0:\[${color}\]m[\u]-> $reset"
You may need to tweek that. Like I said, this is untested so I may have inserted a "\]
" in the middle of a colour code. For my prompt I do the escaping when I initialise the colour variables:
PS1_FG="\[$(tput setaf 223)\]" # Prompt foreground colour (223 = pale orange/brown)
For what it's worth, I can highly recommend using tput
when you're dealing with control codes. It makes your scripts more portable, and (IMHO) is easier to read.