0

Here's my ps1 variable:

export PS1='\e[33;1m\u@\h\]: \e[31m\W\e[0m\e[0;32m$(parse_git_branch)\e[0m$\] '

Where parse_git_branch is a function that shows what branch I'm currently on in git, such as (master).

I've also set this in my .bashrc

stty columns 500

The behavior is really weird - in VS code if I make my integrated terminal really small, the line wrapping works correctly. If it's above a certain size, it starts overwriting itself on the same line.

Any idea what I'm doing wrong?

edit

Ben was correct below - I had to make sure the escape characters matched up and wrapped the entire thing in brackets. This seems to work:

export PS1='\[\e[33;1m\u@\h\]: \e[31m\W\e \e[0;32m$(parse_git_branch)\] \]\e[0m$\]\] \]'
yoursweater
  • 1,883
  • 3
  • 19
  • 41
  • 1
    You have to escape all non-printing sequences with `\[...\]`, but you only have the closing `\]` or nothing at all. – Benjamin W. Apr 22 '19 at 18:58
  • `\u` et al. aren't really non-printing sequences. `bash` knows how long the result will be, so they (and the literal character `@`) need to be left *out* of the `\[...\]` groups. – chepner Apr 22 '19 at 19:44

0 Answers0