12

Newbie question, I recently changed my PS1 into this:

RESET="\[\017\]"
NORMAL="\[\033[0m\]"
YELLOW="\[\033[0;33m\]"
CYAN="\[\033[0;36m\]"

export PS1="\[$RESET\]\u@\h:\[$CYAN\]\w\[$YELLOW\]\$(__git_ps1)\[$NORMAL\] \$ "

But now I get a line wrapping error. I created a gif to explain the problem:

enter image description here

Any ideas what might be wrong?

hampusohlsson
  • 10,109
  • 5
  • 33
  • 50

3 Answers3

5

I think you're double-quoting your escape codes with [ and ]. Try this one:

export PS1="$RESET\u@\h:$CYAN\w$YELLOW\$(__git_ps1)$NORMAL \$ "
konsolebox
  • 72,135
  • 12
  • 99
  • 105
2

The wrapping error occurs whenever a non-printing character is not escaped (such as the escape codes that change the prompt color). It also occurs when the locale is set to something that does not understand unicode characters and the prompt includes them. An example would be non-breaking spaces. When the locale is "C" and there are unicode characters in the prompt, the shell thinks more characters are being printed than truly are, and the prompt wraps around prematurely.

bu11d0zer
  • 433
  • 4
  • 13
1

shopt -s checkwinsize this should fix your problem. This will set the variable checkwinsize on. This is set by default in /etc/bashrc however since you're using your custom .bashrc file you can put this code in there or in your .bashrc file load the /etc/bashrc by adding . /etc/bashrc at the top of your .bashrc file.

hacitmacit
  • 11
  • 2