Note: iTerm2 provides support for italic text, whereas Apple’s Terminal does not. That’s why this solution discusses only iTerm2.
iTerm 2
1. Enable support for italic text
Preferences > Profiles > Text > Italic text allowed
2. Create TERMINFO entry with italics support
-
Create temporary file
terminfo
with following content:xterm-256color-italic|xterm with 256 colors and italic, sitm=\E[3m, ritm=\E[23m, use=xterm-256color,
-
Create a new entry in the
TERMINFO
databasetic terminfo
-
Delete the temporary
terminfo
file
3. Bind iTerm2 to new TERMINFO entry
Preferences > Profiles > Terminal > Report Terminal Type: > xterm-256color-italic
4. Test it
Close and reopen iTerm2, then try:
echo `tput sitm`italics`tput ritm`
If the output is printed in italicised, then iTerm2 is now capable of printing italic text. Furthermore:
echo $TERM
should now output xterm-256color-italic
Sources
Tmux
After italic text is enabled in iTerm2, it works in iTerm2, but not in tmux. This is because tmux uses a different TERM
than the terminal in which it is running. To enable italic text in tmux as well, do the following.
1. Create a new TERMINFO entry
-
Create temporary file
terminfo
with following content:tmux|tmux terminal multiplexer, ritm=\E[23m, rmso=\E[27m, sitm=\E[3m, smso=\E[7m, Ms@, use=xterm, use=screen, tmux-256color|tmux with 256 colors, use=xterm-256color, use=tmux,
-
Create new entry in the
TERMINFO
database:tic -x terminfo
-
Delete the temporary
terminfo
file
2. Bind tmux to new TERMINFO entry
Set the following in ~/.tmux.conf
:
set -g default-terminal "tmux-256color"
set -as terminal-overrides ',xterm*:sitm=\E[3m'
3. Test it
Close and reopen tmux, then try:
echo `tput sitm`italics`tput ritm`
If the output is printed in italicised, then tmux is now capable of printing italic text. Furthermore:
echo $TERM
should now output tmux-256color
Sources
- https://www.bountysource.com/issues/36925710-tic-can-t-open-when-trying-to-enable-italics-according-to-faq
- http://apple.stackexchange.com/a/249385
Caveat
If using ssh
, then the value of the TERM
variable is imposed onto the remote system, which many not have it in its database. To fix this problem, we can put the following into ~/.bashrc
:
alias ssh="TERM=xterm-256color ssh"