Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@bbqtd
Last active April 2, 2024 21:24
Show Gist options
  • Save bbqtd/a4ac060d6f6b9ea6fe3aabe735aa9d95 to your computer and use it in GitHub Desktop.
Save bbqtd/a4ac060d6f6b9ea6fe3aabe735aa9d95 to your computer and use it in GitHub Desktop.
Installing tmux-256color for macOS

Installing tmux-256color for macOS

  • macOS 10.15.5
  • tmux 3.1b

macOS has ncurses version 5.7 which does not ship the terminfo description for tmux. There're two ways that can help you to solve this problem.

The Fast Blazing Solution

Instead of tmux-256color, use screen-256color which comes with system. Place this command into ~/.tmux.conf or ~/.config/tmux/tmux.conf(for version 3.1 and later):

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

The screen-256color in most cases is enough and more portable solution. But it does not support any italic font style.

The Right Way

Unfortunately, The latest (6.2) ncurses version does not work properly. Make sure to use ncurses which comes with macOS:

$ which tic
/usr/bin/tic

If you see another path to terminal info compiler, you must fix the $PATH for a shell, or uninstall a local ncurses by using a package manager.

Let's download and unpack the latest nucurses terminal descriptions:

$ curl -LO https://invisible-island.net/datafiles/current/terminfo.src.gz && gunzip terminfo.src.gz

And compile tmux-256color terminal info. The result is placed into ~/.terminfo:

$ /usr/bin/tic -xe tmux-256color terminfo.src

If you want to use tmux-256color for all users, use sudo. The result is placed into /usr/share/terminfo:

$ sudo /usr/bin/tic -xe tmux-256color terminfo.src

You may also to compile few more infos, it is up to you:

$ /usr/bin/tic -xe alacritty-direct,tmux-256color terminfo.src

If you see something like:

"terminfo.src", line 1650, terminal 'pccon+base': enter_bold_mode but no exit_attribute_mode
"terminfo.src", line 1650, terminal 'pccon+base': enter_reverse_mode but no exit_attribute_mode

do not worry, all should be fine. Make sure that you can use the compiled description:

$ infocmp -x tmux-256color

And finally, set default terminal in tmux configuration file:

set-option default-terminal "tmux-256color"

RGB Colors

Also, do not forget to enable RGB colors (24 bit colors, or true colors, as you like). The $TERM outside tmux must support 256 colors. Also, it must contains Tc or RGB flag in terminfo description:

$ tmux info | grep -e RGB -e Tc

If both are missing, then you need to override terminal description in tmux configuration file:

set-option -a terminal-overrides ",XXX:RGB"

where XXX is a terminal outside tmux, like xterm-256color. And finally, terminal-overrides suports a pattern matching:

set-option -a terminal-overrides ",*256col*:RGB"

If you use Alacritty terminal, make sure the $TERM outside tmux is alacritty-direct. The alacritty terminal description does not have RGB flag. Otherwise, override description:

set-option -a terminal-overrides ",alacritty:RGB"
@brandoncc
Copy link

You are amazing, thank you!!!

@xanoni
Copy link

xanoni commented Aug 12, 2021

YOU SAVED MY PRODUCTIVITY AND SANENESS THANK YOU SIR

@ayamir
Copy link

ayamir commented Feb 3, 2022

Thanks!

@mikiya09
Copy link

mikiya09 commented Feb 4, 2022

Thank you!!!!!!!!!!!!!!!!!!!!!!

@ggustafsson
Copy link

I followed this guide and I thought it worked but after a few weeks I realised that the generated tmux-256color file is a bit broken, try running the "dialog" program and you'll get some messy stuff. Generating a terminfo file based on the Tmux developer nicm's gist (https://gist.github.com/nicm/ea9cf3c93f22e0246ec858122d9abea1) instead of the Ncurses terminfo source however works great (as far as I can tell, dialog + italic font works). tic -x <gist>. @carlocab has already mentioned this.

My tmux-256color file can be found here if anybody needs it (until it is included in macOS): https://github.com/ggustafsson/Dot-Files/blob/master/Misc/tmux-256color

(Note: I'm still on Big Sur. I don't have a clue if the situation has been remedied in Monterey or not yet.)

@YodaEmbedding
Copy link

YodaEmbedding commented May 12, 2022

A good resource which explains each step in detail. Works for me on MacOS 10.15:
https://gpanders.com/blog/the-definitive-guide-to-using-tmux-256color-on-macos/

A short gist for MacOS <10.15:
https://gist.github.com/joshuarli/247018f8617e6715e1e0b5fd2d39bb6c

@deCHN
Copy link

deCHN commented Jun 17, 2022

With macOS 12.4 and Apple M1 chip, Tmux 3.3a, I cannot enable the RGB / Tc color with this set in tmux.conf:

set default-terminal "screen-256color"
set -a terminal-overrides ",*256col*:RGB"

Restart tmux server and run:

$ tmux info | grep -e RGB -e Tc
 197: RGB: [missing]
 223: Tc: [missing]
$ echo $TERM
screen-256color

What do I still miss to enable RGB color? Thanks!

@tparvu
Copy link

tparvu commented Jun 17, 2022

Thanks much! Worked for me on Darwin Kernel Version 21.5.0.

@nkhlmn
Copy link

nkhlmn commented Jun 18, 2022

I'm on macOS 12.4 and when I run /usr/bin/tic -xe tmux-256color terminfo.src I get tic: Can't open terminfo.src.
Anyone know what the issue is?

EDIT:
The following method worked for me:

$ /*/*/Cellar/ncurses/6.3/bin/infocmp -x tmux-256color >tmux-256color.src
$ sudo /usr/bin/tic -x tmux-256color.src

Outlined here: tmux/tmux#3218

@dafevara
Copy link

Thank you! 👏

@mustafaergul
Copy link

Thanks, that helped a lot!

@moods445
Copy link

Thanks

@ntananh
Copy link

ntananh commented Nov 19, 2022

Thanks a lot

@DaniilSintsov
Copy link

Thank you very much! I've been trying to find a solution all day long

@weimeng23
Copy link

thanks a lot!

@cattyhouse
Copy link

cattyhouse commented Apr 9, 2023

if there is homebrew ncurses, use it, else use the file from invisible-island.net.

save as zsh function and run it.

update_terminfo () {
    local x ncdir terms
    ncdir="/opt/homebrew/opt/ncurses"
    terms=(alacritty-direct alacritty tmux tmux-256color)

    mkdir -p ~/.terminfo && cd ~/.terminfo

    if [ -d $ncdir ] ; then
        # sed : fix color for htop
        for x in $terms ; do
            $ncdir/bin/infocmp -x -A $ncdir/share/terminfo $x > ${x}.src &&
            sed -i '' 's|pairs#0x10000|pairs#32767|' ${x}.src &&
            /usr/bin/tic -x ${x}.src &&
            rm -f ${x}.src
        done
    else
        local url
        url="https://invisible-island.net/datafiles/current/terminfo.src.gz"
        if curl -sfLO $url ; then
            gunzip -f terminfo.src.gz &&
            sed -i '' 's|pairs#0x10000|pairs#32767|' terminfo.src &&
            /usr/bin/tic -xe ${(j:,:)terms} terminfo.src &&
            rm -f terminfo.src
        else
            echo "unable to download $url"
        fi
    fi
    cd - > /dev/null
}

result

tree -a ~/.terminfo

/Users/^_^/.terminfo
├── 61
│   ├── alacritty
│   └── alacritty-direct
└── 74
    ├── tmux
    └── tmux-256color

3 directories, 4 files

EDIT: add sed 's|pairs#0x10000|pairs#32767|' to fix htop color according to info provided by @carlocab

@carlocab
Copy link

carlocab commented Apr 9, 2023

Note: please follow the instructions here if you don’t want to end up with term info entries that are subtly broken.

If the link above doesn’t work: https://gpanders.com/blog/the-definitive-guide-to-using-tmux-256color-on-macos/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment