Bash prompt not wrapping as expected

bashprompt

Here it is:

Captures git branch for prompt:

parse_git_branch() {
    git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
export PS1="\W\[\033[0;31m\]\$(parse_git_branch)⚡️\[\033[0;39m\] "

It is not wrapping lines in my terminal correctly (it runs over the current line when it is supposed to wrap to the next line) and it also inserts a random alpha character (that cannot be deleted) at the beginning of my prompt (yet, this has no effect of commands I am trying to execute).

Best Answer

If you're like me and you MUST have the emoji in your prompt, this fixed the line wrap problem for me:

PS1="\[⚡️\]"

Essentially, this makes the lightning bolt not be counted in the prompts length, better explained in this askubuntu thread.

Related Question