3

So whenever I try to type a command and it gets too long. The command just overwrites itself. I have tried multiple things like:

  • shopt
  • shopt -s checkwinsize
  • Ctrl+L
  • Alt+L
  • Space+L
  • Alt+Space+L
  • eval $(resize)
  • if [ $(tty) == '/dev/ttyS0' ]; then trap resize DEBUG; fi

and I have enclosed my color command in the ~/.bashrc file in [] but still no luck. Any help would be appriciated.


I found the source of the problem: The issue lies with my PS1 line on my ~/.bashrc file.

 export PS1="[\e[0;32m[\u@\h \W]\$ "

is what I have in my file currently.

dessert
  • 40,956

1 Answers1

6

Based on this answer on "How do I get long command lines to wrap to the next line?", you have a problem in your PS1:

export PS1="[\e[0;32m[\u@\h \W]\$ "

So change \e[0;32m to \[\e[0;32m\]:

export PS1="\[\e[0;32m\][\u@\h \W]\$ "

Also, you'll probably want to remove that zero in \e[0;32m since it does nothing, and* reset the color at the end of the prompt with \e[m:

export PS1="\[\e[0;32m\][\u@\h \W]\$\[\e[m\] "

*Correction from Egmont's comment:

That 0 resets the attributes, it makes a difference if the previously executed command didn't clean up after itself, e.g. left a nondefault background color, bold/italic/etc. attribute. In that case it's reverted. Under "normal" circumstances it doesn't do anything, but is harmless.

wjandrea
  • 14,504