Problem setup
I have a PS1 definition using nerdfonts. However, sometimes when ssh’ing into them from some machines, the special characters are not expanded. In this case, I will like to replace the special character for a default one.
Question
How can I check if a unicode character has a corresponding glyph?
In particular, I’m looking for a bash solution. So, something standard and portable will be a plus.
For instance, I’m trying something in the lines of
__default_symbol(){
# check if the unicode character was expanded (shouldn't contain the u character)
if [[ "$1" == *"u"* ]]; then echo $2
else echo $1
fi
}
# Symbols
BRANCH_SYMBOL=$(__default_symbol $'uf126' '[b]')
However, checking if the unicode was not expanded is not reliable. Sometimes, I see that the unicode was not expanded and then I default into the characters. But some other time, it is expanded but there is no corresponding glyph.
How can I properly check if the unicode has a corresponding glyph?
Also, I’m not sure if checking if the unicode is been expanded is the correct approach. I’m not familiar on how the unicode and the existing glyphs relate when printed in the terminal.