tmux QOL settings

a.k.a. tmux config for screen users


Install powerline, A fancy status line for tmux

sudo pip3 install powerline-status

Copy powerline config files to a locally editable place

mkdir -p ~/.config/powerline
cp -r /lib/python3.10/site-packages/powerline/config_files/* ~/.config/powerline

Now you can edit ~/.config/powerline/themes/tmux/default.json to customize your tmux status bar. For example I don’t want to see the system uptime or load in the status bar so I remove the sys.uptime and sys.system_load blocks.

Powerline fonts

In order to see some of the symbols that powerline uses you will need a supported font. I’ve found that the Hack powerline font is easy enough on the eyes. You’ll need to install it in macOS in order to use it with iTerm2 and you’ll need to install it in Windows in order to use it with PuTTY

Configure iTerm and PuTTY to use 256 colors and the new font

You’ll want to enable 256 color support otherwise you’ll be stuck using only 16 colors and that looks terrible.

For iTerm2 you’ll need to go to Settings -> Profiles -> Terminal and change “Report Terminal Type” to xterm-256color. Then go to Settings -> Profiles -> Text and change “Font” to Hack.

For PuTTY you’ll need to go to Configuration -> Connection -> Data and change “Terminal-type string” to putty-256color. Then go to Configuration -> Window -> Appearance -> Font settings and change “Font:” to Hack.


# mouse support

set -g mouse on

# prefix

unbind C-b                   # \
set-option -g prefix C-a     #  > Change prefix from `Ctrl-b` to `Ctrl-a`
bind-key C-a send-prefix     # /
bind a send-prefix           # Make it so `Ctrl-a a` mimics bash's ctrl-a (move cursor to beginning of line)

# sessions

bind C new-session           # `Ctrl-a C` to create a new session
bind P switch-client -p      # `Ctrl-a P` for previous session
bind N switch-client -n      # `Ctrl-a N` for next session
bind S choose-tree           # `Ctrl-a S` to bring up a choose session screen
set -g detach-on-destroy off # Go to previous session instead of detaching

# windows

unbind w
unbind &
unbind '"'
bind '"' choose-window                                       # `Ctrl-a "` to bring up a choose window screen
bind A command-prompt -I "#W" "rename-window '%%'"           # `Ctrl-a A` to name your current window
bind C-a last-window                                         # `Ctrl-a Ctrl-a` to go to previous window
bind k confirm-before -p "kill window #W? (y/n)" kill-window # `Ctrl-a k` to kill (an unresponsive) window
set -g automatic-rename on                                   # Automatically name your window (unless you've manually named it)
set -g history-limit 50000                                   # Window scrollback size
set -g renumber-windows off                                  # Don't renumber windows if you close one

# panes

unbind %
bind | split-window -h                       # `Ctrl-a |` to split window vertically
bind - split-window -v                       # `Ctrl-a -` to split window horizontally
bind -n M-Left select-pane -L                # `Alt-LeftArrow` to move to pane to the left
bind -n M-Right select-pane -R               # `Alt-RightArrow` to move to pane to the right
bind -n M-Up select-pane -U                  # `Alt-UpArrow` to move to pane above
bind -n M-Down select-pane -D                # `Alt-DownArrow` to move to pane below
bind s set-window-option synchronize-panes   # `Ctrl-a s` to type in all panes at once
# Note, you can use `Ctrl-a z` to zoom into a pane (make the pane full screen).  Also to zoom out.

# term

# Set tmux-256color for tmux for reasons:
set -g default-terminal "tmux-256color"

# Make sure true color capability "Tc" is set for xterm
set -ga terminal-overrides ",xterm*:Tc"

# powerline

source /lib/python3.10/site-packages/powerline/bindings/tmux/powerline.conf

Color test script

Here’s a script to make sure your terminal is working with true color. You may want to run this script both before and after running tmux to verify colors are working correctly

awk -v term_cols="${width:-$(tput cols || echo 80)}" 'BEGIN{
    for (colnum = 0; colnum<term_cols; colnum++) {
        r = 255-(colnum*255/term_cols);
        g = (colnum*510/term_cols);
        b = (colnum*255/term_cols);
        if (g>255) g = 510-g;
        printf "\033[48;2;%d;%d;%dm", r,g,b;
        printf "\033[38;2;%d;%d;%dm", 255-r,255-g,255-b;
        printf "%s\033[0m", substr(s,colnum%2+1,1);
    printf "\n";