0

I was trying to add some color and the time to my PS1 prompt on Debian 10 in my ~/.bashrc file. It initially looks right, but if I type a line that's more than about 40 characters the cursor moves to the beginning of the line (the first character of the prompt itself) and typing continues from there. I think something isn't escaped correctly, but I can't see what it is.

SH_OFF='\[\033[00m\]'

SH_BLACK='\[\033[1;30m\]'
SH_BLUE='\[\033[1;34m\]'
SH_GREEN='\[\033[1;32m\]'
SH_CYAN='\[\033[1;36m\]'
SH_RED='\[\033[1;31m\]'
SH_PURPLE='\[\033[1;35m\]'
SH_BROWN='\[\033[1;33m\]'
SH_YELLOW='\[\033[1;33m\]'

PS1="${debian_chroot:+($debian_chroot)}$SH_GREEN\u@\h \t$SH_OFF $SH_YELLOW\w$SH_OFF \$ "
raphael75
  • 723
  • Sometimes there can be this kind of problem when dealing with DOS format files, can you do a dos2unix on your files ? – Philippe Jan 23 '20 at 14:09
  • It happens if I type something like "ls -l /etc/apt/sources.list.d | grep cassandra". Somewhere around "andra" would move back to the beginning of the line. – raphael75 Jan 23 '20 at 14:47
  • 1
    Can you take a look at this : https://unix.stackexchange.com/questions/105958/terminal-prompt-not-wrapping-correctly – Philippe Jan 23 '20 at 15:00

1 Answers1

0

Well, it looks like I had to use double-quotes. This appears to have fixed it:

SH_OFF="\[\033[00m\]"

SH_BLACK="\[\033[1;30m\]"
SH_BLUE="\[\033[1;34m\]"
SH_GREEN="\[\033[1;32m\]"
SH_CYAN="\[\033[1;36m\]"
SH_RED="\[\033[1;31m\]"
SH_PURPLE="\[\033[1;35m\]"
SH_BROWN="\[\033[1;33m\]"
SH_YELLOW="\[\033[1;33m\]"
raphael75
  • 723