4

Today I noticed I did not have 256 color support in Weechat. I decided this would be a quick fix. It isn't.

First thing I googled was how to test the color support in terminal. I have installed colortest on my local machine and when I run it it shows me 256 colors. However, when I run echo $TERM it kept showing me xterm.

Since I don't know the details about all these things I tried to configure it such that it matches up with every tutorial on the topic. They all say it should give me screen-256colors.

First thing I did was add this to my .zshrc file:

# If the $term variable is xterm, change it to 256 colors!
if [ "$TERM" = "xterm" ]; then
    # No it isn't, it's gnome-terminal
    export TERM="xterm-256color"
fi

It says xterm-256colors instead of screen-256colors. That's okay, some tutorial told me to do that.

I start a new terminal, echo $TERM and I notice that it is indeed set. Fire up a tmux and see what that tells me when I type echo $TERM. It says screen. So that should show me screen-256colors for it to work properly in weechat. So next I tried to change the xterm-256colors in my .zshrc file to screen-256colors but when I do that, I get garbled output. See the screenshot.

enter image description here

So next I googled on how to change the variable for tmux. I found this link. It shows an option to configure tmux to use 256 colors. It is an option that is shown in almost all the tutorials.

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

So I tried it, yet it didnt change a thing. So I googled around some more and found this question. Quote:

Tmux is relatively picky about having a terminal set correctly. If you can, set the term value in gnome-terminal's configuration, not in your .bashrc. Failing that, surround those settings with a check for "screen" or "screen-256color" TERM, and don't reset them in that case.

Okay, so I understand that outside of tmux I should not use screen* values for $TERM. That's okay because it is set to xterm-256colors. Then it clearly states that I should not override the $TERM variable if it is set to screen. Which I have made sure of using the if test in my .zshrc file.

The thing that mainly confuses me is that 256 colors actually work in tmux. See the screenshot below. When I run echo $TERM inside tmux it shows screen. When I run colortest-256 it shows me all colors properly. Yet, I think weechat bases itself on the $TERM variable to show colors. And because I run it inside tmux with $TERM set to screen it assumes I don't have 256 color support.

enter image description here

I am stumped on how to solve this issue. All I wanted were some colors in weechat :>

For completeness below are my two configuration files.

.zshrc

# Path to your oh-my-zsh installation.
export ZSH=/home/christophe/.oh-my-zsh
ZSH_THEME="flazz"
plugins=(git command-not-found common-aliases dircycle lein)


# Show dots for progress
COMPLETION_WAITING_DOTS="true"

##########
## PATH ##
##########

# Export directory if it exists.
#if [ -d "/usr/local/go/bin" ]; then
#    export PATH=$PATH:/usr/local/go/bin
#fi

#############
## ALIASES ##
#############

alias randompass="< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c${1:-32};echo;"

############
## TWEAKS ##
############

# Disable shared history
setopt no_share_history


# Start existing or new tmux session each shell startup
#[[ $TERM != "screen" ]] && exec tmux attach -d
alias chat='tmux attach -dt weechat || tmux new -s weechat \; new-window htop'


# If the $term variable is xterm, change it to 256 colors!
if [ "$TERM" = "xterm" ]; then
    # No it isn't, it's gnome-terminal
    export TERM="xterm-256color"
fi


######################
# User configuration #
######################

export PATH="/home/christophe/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"
source $ZSH/oh-my-zsh.sh

.tmux.conf

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

1 Answer 1

2

First of all I'd like to confirm what you've already figured out, namely that directly under gnome-terminal (that is, outside of tmux or screen) you should set TERM=xterm-256color, whereas inside tmux or screen it should be set to TERM=screen-256color.

Apparently your .zshrc segment properly sets it for the shell that's run directly by gnome-terminal.

I'm not sure what needs to be put in .tmux.conf, I have solved it in my .bashrc similarly to your .zshrc fragment for xterm-256color. I also remove TERMCAP which is set by screen and causes some problems, but apparently tmux doesn't set it so it shouldn't make a difference for you.

if [ "$TERM" = "xterm" ]; then
    export TERM=xterm-256color
fi
if [ "$TERM" = "screen" -o "$TERM" = "screen-256color" ]; then
    export TERM=screen-256color
    unset TERMCAP
fi

Does this solve the problem for you?

By the way, instead of this snippets, copying your .tmux.conf also sets this properly for me (on Vivid), so you're on the right track, it should work. Is there maybe something else sourced by your zsh (e.g. the global config, or oh-my-zsh) that reverts to the 8/16-color TERM=screen?

1
  • The update you gave me worked indeed! Everything is working excellent. Thank you for the feedback! May 1, 2015 at 9:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .