1

I want to italicize my prompt (specifically the right prompt/RPROMPT) for zsh using oh-my-zsh, in iTerm2, and so far have had problems doing so. I have checked that the terminal can output and view italicized fonts with echo -e "\e[3mitalic\e[0m".

Things I have tried so far :

  1. RPROMPT = '\e[3m Hello \e[0m' : the output is a literal quote \e[3m Hello \e[0m
  2. from here, I tried
 HELLO = Hello
 RPROMPT = '\e[3m $Hello \e[0m'`

and the output still has the \e[3m and \e[0m parts

  1. from an example, I tried using \x1b[3m rather than \e[3m : still outputs \x1b[3m and \x1b[0m

  2. I found this page but I don't understand what I'm looking at/what I'm supposed to do.

I would like to get the italic format working, so any help is greatly appreciated.

oiolosse
  • 13
  • 4
  • Thank you, the dollar sign in front was exactly what I needed! Do you want to turn your comment into an answer, and I'll mark this as answered? – oiolosse Jun 05 '21 at 07:50

3 Answers3

0

You can use RPROMPT=$'string with special escaping' (See bash manual)

It may have a few issues such as the left prompt getting edited.

  • 1
    Based on your answer, I managed to find a solution that does not mess with the left prompt. You need to use a string quote ```%{ ... %}``` to wrap around the escape sequence formatting, e.g. ```RPROMPT=$'%{\x1b[3m%} hello %{\x1b[0m%}'``` – oiolosse Jun 05 '21 at 09:28
0

After further testing based on GrapeApple's answer, I found a solution that does not mess with the left prompt. Per zsh documentation, you need to use a string quote %{ ... %} to wrap around the escape sequence formatting, e.g. :

RPROMPT=$'%{\x1b[34;1;3m%} hello %{\x1b[0m%}'

oiolosse
  • 13
  • 4
0

For better compatibility (in case you run your zsh one day with a different kind of TERM), I would not hard-code the escape sequences, but use something like

RPROMPT="$(tput sitm) Hello $(tput sgr0)"

See man terminfo for the meaning of sitm and sgr0.

user1934428
  • 19,864
  • 7
  • 42
  • 87