I'm using Gnome Terminal to connect via SSH to my server. My account on the remote server (which is Ubuntu) uses bash. My bashrc contains a line that sets the shell prompt to include my current git branch if applicable:
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
export PS1="\u@\h: \[\033[32m\]\w\[\033[00m\]\$(parse_git_branch)\$ "
When I am inside a git repo, my terminal stops wrapping properly. Long commands that should wrap onto the second line instead wrap to the beginning of the line they started on and start printing right on top of my prompt.
I don't experience wrapping issues except when my working directory is inside a git repo (i.e., when parse_git_branch
's output is not empty).
I know that non-printable characters should be enclosed in \[
and \]
so that the shell (or terminal?) knows not to count them towards the length of the prompt. I'm fairly confident that the "export" line has correctly done that... but my regex-fu is not strong enough to understand what that sed command is doing, and I think it isn't inserting the non-printable characters properly.
This question is extremely similar (and even uses the same parse_git_branch
function, which we got from here), but the other question involved having an emoji in the prompt, which is not the case for me.
Does anyone know what is wrong with my prompt?