I'd like to add unicode characters to my Zsh prompt to customise the theme.
I've read articles like this one (https://scriptingosx.com/2019/07/moving-to-zsh-06-customizing-the-zsh-prompt/) that explain that you need to change the PROMPT variable, which I have tried. However, when it comes to printing Unicode characters in the prompt, the shell returns that text of the character (e.g. 'U+1F600'), and not the character graphic icon itself (š).
I was wondering if this is something that is possible in Zsh?
I was inspired by a prompt that looks like this:
Inserting Unicode characters To insert a Unicode character, type the character code, press ALT, and then press X. For example, to type a dollar symbol ($), type 0024, press ALT, and then press X.
Hold down CTRL-SHIFT-u and you will see an underlined u character that is waiting for input. Type the hexadecimal Unicode value and press space. http://unicode.org/charts/ is a full collection of charts that list all Unicode characters with their codes.
If the PROMPT_SUBST option is set, the prompt string is first subjected to parameter expansion, command substitution and arithmetic expansion. See section Expansion. Certain escape sequences may be recognised in the prompt string. If the PROMPT_BANG option is set, a `!
Use the \U
escape, which can be followed by a hexadecimal value of 1-8 digits (though Unicode as currently defined would only ever required 6 digits, as it only allows code points up to 10FFFF).
% print '\U1f600'
š
For a prompt, you need to use $'...'
quoting to cause the escape to be expanded (the print
command does that itself):
% PS1=$'%m %1~ \U1f600 %# '
myhost ~ š %
As in other contexts, different kinds of quoting can be combined in a single assignment. E.g.,
PS1='%m %1~ '$'\U1f600'' %# '
is equivalent to the above.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With