New linux user here.
My bash prompt looks like this:
export PS1=$"\[\e[1;32m\d \t \e[1;33mฅ^\e[m\e[1;36mᵒ\e[m\e[1;33mﻌ\e[m\e[1;36mᵒ\e[m\e[1;33m^ฅ \e[1;35m\W\e[1;32m$\]"
(it's a kitty ฅ^ᵒﻌᵒ^ฅ
)
Now that I've added the ]
to the end of the string, it no longer deletes my bash prompt characters when the prompt is empty. However, it does delete my bash prompt once I start typing a command and then press backspace.
Is there a way to prevent this, or is this just a bash thing?
Thanks!
The \[...\]
indicates that the contained part does not take up any space in the prompt. So, they're to be used for the xterm control sequences (\e[1;32m
, etc.), not the prompt text (\d
, \t
, etc.). Try something like:
PS1='\[\e[1;32m\]\d \t\[\e[1;33m\]ฅ^\[\e[m\e[1;36m\]ᵒ\[\e[m\e[1;33m\]ﻌ\[\e[m\e[1;36m\]ᵒ\[\e[m\e[1;33m\]^ฅ\[\e[1;35m\]\W\[\e[1;32m$\]'
If your entire prompt is wrapped in \[...\]
, then bash thinks your prompt takes no space at all, and typing begins at the start of the line.
(You don't need to export PS1
, by the way.)