How to italicise text in zsh prompt?

2.7k views Asked by At

I'm struggling to understand how to italicise a section of my zsh prompt (using prezto).

My prompt currently looks like this:

PROMPT='%F{yellow}%T %F{magenta}${SSH_TTY:+%n@%m }%F{cyan}%1~%f${vcs_info}\ 55 %(!.%B%F{red}#%f%b.%B %(?.%F{green}.%F{red})❯%f%b) '

Say I wanted to make the vcs_info italic, how would I do that?

1

There are 1 answers

0
kba On BEST ANSWER

In theory, the ANSI escape code \e[3m sets the italic SGR. So to answer your question, this should work:

PROMPT='...%{\x1b[3m%}${vcs_info}%{\x1b[0m...%}'

Unfortunately, italic text is not widely supported in terminals emulators. Some just ignore it, others inverse the colors instead of italicizing text. To test your terminal emulator, check the output of echo -e "\e[3mitalic\e[0m". If that doesn't print italic, you need to use a terminal emulator that does, such as gnome-terminal.