TheTeaRex
TheTeaRex

Reputation: 329

tmux is not using screen-256color even it is set in the config file

I am trying to get tmux to use screen-256color instead of xterm-256color, as it is not recommended. But when I am not using tmux, I would like to keep it as xterm-256color

A little bit of my setup, I am currently using iTerm2 and ssh to my development linux box, which is using zsh.

In my ~/.zshrc, I have:

export TERM="xterm-256color"

In my ~/.tmux.conf, I have:

set -g default-terminal "screen-256color"

With this configuraiton, without tmux, echo $TERM returns xterm-256color (which is right) and with tmux, echo $TERM is still returning xterm-256color instead of screen-256color.

Is there anything else I need to set in order for this to work?

Thanks!

Upvotes: 5

Views: 5918

Answers (2)

Adaephon
Adaephon

Reputation: 18409

The reason this does not work as expected is, that the zsh session that is started inside tmux overwrites TERM.

You should not set TERM from within in your shell. TERM is the way the terminal informs the shell and other applications about its capabilities (number of colors, key sequences for special keys, etc.). If you change TERM inside the shell, you change the what features the shell and applications expect from the terminal without the terminal itself knowing about it. Oftentimes this may not be an actual issue, but it is better to change the terminal configuration and set the desired value there.

You already did so when setting screen-256color in the configuration of tmux, which is essentially a terminal emulator, too. To do it for iTerm2 (tested with version 3.0.10):

  1. Open the Preferences dialog (in the Menu: iTerm2Preferences, or press +,).
  2. In the dialog go to ProfilesTerminal.
  3. There you can choose the desired value for TERM under Report Terminal Type.

Upvotes: 3

Thomas Dickey
Thomas Dickey

Reputation: 54583

You could modify your .zshrc file to check if you are running in tmux:

[ -z "$TMUX" ] && export TERM=xterm-256color

Upvotes: 0

Related Questions