I have an issue with my terminal prompt line. When the line is too long it wraps on the same line and then Up arrow makes it look even worse.

I have already checked Terminal prompt not wrapping correctly, but it looks like I am apparently closing all the squared brackets for non printable characters.

This is my PS1:

\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot) }\[\033[01;36m\]\u@\h\[\033[00m\]\033[01;34m\]\w\033[00m\][$(type __git_ps1 >/dev/null 2>&1 && __git_ps1 "(%s)")]

Consider this as my standard prompt line


I was able to get

assdasdasdasdasdadasdsadadasdaddasdadadasdadsadasdsa((main))] asdsadsadsadsadasdasdassdasdasdassdasdassdasdasdasdasdasdasdsadsad

I have already checked my .bashrc

I have and shopt -s checkwinsize should autocheck the columns


You've completely banjanxed the Bourne Again shell's idea of what's been printed and what it has to erase/rewrite as it displays command history and lets you edit the command line.

Breaking your prompt down into sections:

  1. \[\e]0;\u@\h: \w\a\] — non-printing characters, properly enclosed
  2. ${debian_chroot:+($debian_chroot) } — printing characters only, presumably
  3. \[\033[01;36m\] — non-printing characters, properly enclosed
  4. \u@\h — printing characters only
  5. \[\033[00m\] — non-printing characters, properly enclosed
  6. \033[01;34m\] — non-printing characters, improperly enclosed so the Bourne Again shell does not know that they are
  7. \w\033[00m\] — an erroneous mixture of printing and non-printing characters
  8. [$(type __git_ps1 >/dev/null 2>&1 && __git_ps1 "(%s)")] — printing characters only, presumably

I've given this advice before, but it is general advice that applies here as well:

  • Use either \e or \033 consistently, for your own sanity.
  • Make your \[ and \] strictly matching non-nesting pairs.
  • Make sure that all non-printing sequences are within \[ and \] (and that, conversely, that all printing sequences are not).

(This is why I personally prefer the Z Shell and its alternative prompt expansion mechanism for when I want wacky coloured prompts. It knows that things like %F{green} aren't printing sequences, without having to be told; and it also works out the correct escape sequences from terminfo, without having them hardwired.)

  • Thanks a lot I modified my PS1 in \[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot) }\[\e[01;36m\]\u@\h\[\e[00m\]\[\e[01;34m\]\w\[\e[00m\][$(type __git_ps1 >/dev/null 2>&1 && __git_ps1 "(%s)")] and now it is perfectly working! I had never really understood how that thing worked until I read you explanation. – melisc Oct 21 '16 at 8:52
  • +1 for the use of banjanxed – Jarrod Roberson Apr 18 '18 at 15:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.