13

I have a bit of an odd issue as far as I can tell. When I use tmux I don't get color within the terminal (all text is white, even for things like ls), but my colors work perfectly for vim and other things like that.

In my .tmux.conf file I have the line set -g default-terminal "screen-256color", which is what most people say solved their problems. I also tried starting tmux by typing tmux -2, but that doesn't change anything.

I'm kind of at a loss at this point, so thanks in advance for any help you can offer!

OS: Ubuntu 16.04

Tmux Version: 2.1

3 Answers 3

18

I can help you solve the symptom, but not the root of the problem. The design of the prompt is configured in the variable PS1.

Outside tmux, this is the value:

$ echo ${PS1} # outside tmux
\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$

This is the value inside tmux:

$ echo ${PS1} # outside tmux
${debian_chroot:+($debian_chroot)}\u@\h:\w\$

to fix the problem, you can run this command inside tmux, and the prompt will immediately look normal for the current window:

PS1='\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '

edit: I solved it by adding the following line to ~/.tmux.conf

set -g default-terminal "screen-256color"
1
  • 1
    The last line saved my time! happy bashing :)
    – Masked Man
    Sep 5, 2019 at 17:53
4

This is a bit of an old one. I resolved this issue by creating a .bash_profile file and sourcing my .bashrc file.

To do this, add source ~/.bashrc to your .bash_profile file.

The problem in my case was due to my bashrc settings not being sourced via tmux. Tmux runs as a login shell so it looks for a .bash_profile file or a .bash_login file. My colours were being set in my .bashrc file.

3
  • 1
    this is the only answer that worked for me. Thx. Do you know you to use a theme in tmux? For exmaple this: github.com/seebi/tmux-colors-solarized
    – otto
    Aug 27, 2020 at 9:21
  • @wwwwwwwwwwww sorry I've only just seen this. Have you figured it out? Nov 18, 2020 at 16:10
  • Great point, this is the answer if you use a .bash_profile Nov 19, 2020 at 22:35
1

A simple way to solve this: open .bash_profile

vi .bash_profile

Save the following config's

export PS1="\[$(tput bold)$(tput setb 2)$(tput setaf 2)\]\u@\h:\w $ \[$(tput sgr0)\]"
  alias ls='ls --color'
  alias dir='dir --color'
  alias vdir='vdir --color'
  alias grep='grep --color'
  alias fgrep='fgrep --color'
  alias egrep='egrep --color'

Source the bash profile

source .bash_profile

There will be colours on tmux

You must log in to answer this question.

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