tmux QOL settings

a.k.a. tmux config for screen users

../_images/tmux.png

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.

~/.tmux.conf

#
# 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 -g default-terminal "tmux-256color"
set -ga terminal-overrides ",xterm-256color*:Tc"

#
# powerline
#

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

Python color test script

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

import sys
import os

def echo(msg):
    os.system('echo -n "' + str(msg) + '"')

def out(n):
    os.system("tput setab " + str(n) + "; echo -n " + ("\"% 4d\"" % n))
    os.system("tput setab 0")

# normal colors 1 - 16
os.system("tput setaf 16")
for n in range(8):
    out(n)
echo("\n")
for n in range(8, 16):
    out(n)

echo("\n")
echo("\n")

y=16
while y < 231:
    for z in range(0,6):
        out(y)
        y += 1

    echo("\n")


echo("\n")

for n in range(232, 256):
    out(n)
    if n == 237 or n == 243 or n == 249:
        echo("\n")

echo("\n")
os.system("tput setaf 7")
os.system("tput setab 0")