OpenBSD with tmux

· 5min · Dan F.
Table of Contents

Being able to take off from work, and the next morning, be able to hop back into my tmux session from the day before is truly lifechanging. I used a custom screen config for a little while before stumbling across tmux. I read into tmux one day at work, and was simply amazed at how much easier it was to configure than screen! This led me to conduct an in-depth comparison between tmux and screen. Did you know, screen has some 254 known bugs? Some go back to 2005 the last time I checked.

Tmux is an active project that is significantly easier to configure, and just as stable in my experience.

Please keep in mind that this configuration was written and thoroughly tested, through every day use, on putty.

The config maps ctrl+a as the new prefix, to match that of screen.

The gist of the usage is shown below:

  • ctrl + up will create a new window
  • ctrl + left or right will move between windows
  • ctrl + down will prompt if you would like to close the window
  • alt + up will create a new pane
  • alt + left or right will move between panes
  • alt + down will prompt if you would like to close the pane

Most of the other options within the config have been commented, but I will continue to add in more comments.

.tmux.conf

####################
### Reset Prefix ###
####################

set -g prefix C-a


###################
### Unbind keys ###
###################

unbind A
unbind Up
unbind Down
unbind Left
unbind Right
unbind C-Up
unbind C-Down
unbind C-Left
unbind C-Right
unbind M-Up
unbind M-Down
unbind M-Left
unbind M-Right
unbind C-z

######################
### Global options ###
######################

# Setup tmux paste
bind p paste-buffer

# Set scrollback history to 10K lines
set -g history-limit 10000

# Shorten command delay
set -sg escape-time 1

# Fix ctrl and shift with arrow keys in putty
set-option -g default-terminal "screen-256color"
setw -g xterm-keys on

# Make mouse useful in copy mode
set -g mouse on

# Fix ctrl-left/right key work
set-window-option -g xterm-keys on

# Start window indexing at 1 and not 0
set -g base-index 1

#################
### BIND KEYS ###
#################

bind r source-file ~/.tmux.conf \; display "Reloaded!"

# Configure Ctrl+Arrow keys to create and navigate through windows
bind -n C-Left previous-window
bind -n C-Right next-window
bind -n C-Up new-window
bind -n C-Down confirm-before -p "kill-window #P? (y/n)" kill-window

# Configure Alt+Arrow keys to create and navigate through panes
bind-key -n M-Left select-pane -t :.-
bind-key -n M-Down confirm-before -p "kill-pane #P? (y/n)" kill-pane
bind-key -n M-Right select-pane -t :.+
bind-key -n M-UP split-window -h
bind-key -n C-_ split-window -v

# Configure Ctrl+Space to resize pane
bind Down resize-pane -D 20                  # (Resizes the current pane down by 10 cells)
bind Up resize-pane -U 20                    # (Resizes the current pane upward by 10 cells)
bind Left resize-pane -L 20                  # (Resizes the current pane left by 10 cells)
bind Right resize-pane -R 20                 # (Resizes the current pane right by 10 cells)

#####################
### Function Keys ###
#####################

# Sync panes within window
bind-key -n C-s setw synchronize-panes

# Zoom into pane
bind-key -n C-z resize-pane -Z  

# disable tmux native clipboard
set -sg set-clipboard off

#######################
### Custom Menu Bar ###
######################


set-option -g status on             # turn the status bar on
set -g status-interval 5            # set update freq (default: 15)
set -g status-justify centre        # Center the window list

# Set visual notifications
setw -g monitor-activity on
set -g visual-activity on

# set color for status bar
#set-option -g status-bg colour240
set-option -g status-bg black
set-option -g status-fg yellow
set-option -g status-attr dim

# set window list colors; red for active, white for inactive
set-window-option -g window-status-fg white
set-window-option -g window-status-bg colour236
set-window-option -g window-status-attr dim

set-window-option -g window-status-current-fg brightred
set-window-option -g window-status-current-bg colour236
set-window-option -g window-status-current-attr bright

#set-window-option -g window-status-format "#H "

# set window title
setw -g automatic-rename on
set-option -g set-titles on
set-option -g set-titles-string 'tmux:#I #W'

# don't erase terminal contents on editor exit
set-window-option -g alternate-screen on

# show hostname and IP address on the left side of status bar
set-option -g status-left-length 100
set -g status-left ' #( sysctl -n vm.loadavg ) '

# show session name, window, pane number, date and time on right side
set -g status-right-length 100

set-option -g status-right "%H:%M %Y-%m-%d"         # My original

Has been tested on OpenBSD 6.4

Updated 4/27/2019: Please see newer tmux config here.