'~/.bashrc change PS1 with color converts newline into carriage return first newline

I changed my prompt as:

    c=$(basename $CONDA_DEFAULT_ENV)
    export PS1='[\h] -\e[0;36m$c\e[0;37m (\W) 🤞 \e[0;52m'

In ~/.bashrc.

The first newline is actually carriage return but from the second newline these are actually newlines.

What I refer to the new line is when the command is too long and instead of continuing in a second line, I write on top of the beginning of the prompt line.

What am I doing wrong?

Thank you!



Solution 1:[1]

You have to put escape sequences (or any other sequences that are invisible when printed) around \[ \] for Bash to properly detect prompt length. See bash documentation about prompt.

Something along:

export PS1='[\h] -\[\e[0;36m\]$c\[\e[0;37m\] (\W) ?\[\e[0;52\]m'

? should be fine - Bash should be able to handle multi-byte sequences and properly detect the length of UTF-8 stuff.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 KamilCuk