Reputation: 1396
I want to use an American flag emoji in my bash prompt (i.e. PS1 environment variable). However, the American flag emoji causes the terminal cursor to offset an extra character to the right.
πΊπΈ is comprised of two unicode characters, πΊ and πΈ. I believe terminal is converting this to a mono-spaced emoji character (the flag), yet still allocating space for two characters. How can I achieve my expected cursor position?
I want:
πΊπΈ Desktop akirna π½ ls|
I get:
πΊπΈ Desktop akirna π½ ls |
<< weird space offset before cursor
My ~/.bash_profile
is:
export PS1='πΊπΈ \W \u π½ '
Upvotes: 4
Views: 3415
Reputation: 51
The way your are setting the prompt is not evaluating the escape characters. Add a $ before the string to make it evaluate the escape codes:
pompt$ export PS1='XY \x08: '
XY \x08: echo "Well that didn't work..."
Should become:
pompt$ export PS1=$'XY \x08: '
XY: echo "Escape code success!"
(See Charles Duffy's comment on this answer for why I removed export
.)
The example above sets the prompt to the characters X, Y, [space], [backspace], [colon] resulting in a displayed prompt of just "XY:".
On my system, the flag is rendered as two characters (πΊ and πΈ), so I cannot verify this, but I think adding a backspace (\x08) should work for you:
PS1=$'πΊπΈ \\W \\u π½\x08'
My original answer suggested using a sub-shell as follows:
export PS1=$(printf "XY \x08")
Many thanks to Charles Duffy for his input~
Upvotes: 2
Reputation: 7975
I worked around this by converting the character to hex, and then putting zero width markers around the second part of the character
so for πΊπΈ we get
PS1='\xf0\x9f\x87\xba\[\xf0\x9f\x87\xb8\] '
Upvotes: 0