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
  • 39,982

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,236
  • 4
  • 48
  • 98
  • 2
    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. – egmont Oct 29 '17 at 07:45
  • Just tried that but now about a quarter the way on the second line it rewrites on the second line – Ivan Jones Oct 29 '17 at 17:25
  • @IvanJones It works perfectly for me. Are you sure you have it set up correctly? – wjandrea Oct 29 '17 at 17:36
  • Yes, I went symbol by symbol. Anyways I just decided to give up. I deleted the commands for the colors. – Ivan Jones Oct 31 '17 at 19:39
  • @egmont Thanks! I added that to the answer. I saw your comment when you posted it but forgot to do anything about it at the time, except upvote. – wjandrea Mar 10 '20 at 16:23