Beautiful command line - Tmux

Tue, 8 Oct. 2024     Thomas Bendler     ~ 3 min to read

Tmux is a fantastic tool that will seriously boost your productivity when working in the terminal. The most straightforward and recommended way to install tmux on macOS is using Homebrew.

Install

You can install tmux with this simple command:

brew install tmux

Homebrew will download and install tmux along with any necessary dependencies. Once the command finishes, you can verify the installation by typing:

tmux -V

Usage

This should print the installed tmux version, confirming that it’s ready to go. To start a new tmux session, use the following command:

tmux new -s my_session

To list the active sessions, you can use the following command:

tmux ls

If you would like to connect to an existing session, you can use:

tmux attach -t my_session

Configuration

Tmux itself is configured underneath ~/.config/tmux with the main configuration file tmux.conf. To match the current setup, I use the following configuration (requires tpm which I will explain afterwards):

# Reload tmux config with leader + r
unbind r
bind r source-file ~/.config/tmux/tmux.conf

# Set leader to CTRL + s
unbind C-b
set -g prefix C-s
bind-key C-s send-prefix

# Enable the mouse to resize tmux windows
set -g mouse on

# Split panes using | and -
unbind '"'
unbind %
bind | split-window -h
bind - split-window -v

# Switch panes using Alt-arrow without prefix
bind -n M-Left select-pane -L
bind -n M-Right select-pane -R
bind -n M-Up select-pane -U
bind -n M-Down select-pane -D

# Move the status bar to the top of the window
set-option -g status-position top

# List of plugins to use with tpm
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'fabioluciano/tmux-tokyo-night'
set -g @plugin 'christoomey/vim-tmux-navigator'

# Plugin configuration tokyo-night-tmux
set -g @theme_plugins 'weather,datetime,playerctl'
set -g @theme_plugin_datetime_format '(CW%V) %x %X %Z'
# set -g @theme_left_separator ''
# set -g @theme_right_separator ''

# Initialize tmux plugin manager (need to be at the bottom)
run '/opt/homebrew/opt/tpm/share/tpm/tpm'

As mentioned, to get the configuration working, you need the tmux package manager, also known as tpm. This one can be installed directly from Github:

git clone https://github.com/tmux-plugins/tpm ~/.config/tmux/plugins/tpm

Once installed you need to install the plugins specified in the tmux configuration by:

~/.config/tmux/plugins/tpm/bin/install_plugins

Followed by:

~/.config/tmux/plugins/tpm/bin/update_plugins all

Now, tmux is functional with a more convenient ladder key and looks beautiful, can’t be much better.

Beautiful command line



Share on: