How To

Proper Way To Customize Tmux on Linux and macOS

Tmux is an acronym for Terminal MUltipleXer. This acts as a window manager for your terminal. In other words, it can be used to create multiple sessions within a single terminal window. This is so vital since you can have several applications or commands executed side by side without requiring you to run a separate terminal.

The features provided by Tmux are:

  • Window Splitting: it allows users to split the terminal onto multiple panels either horizontally or vertically. This makes it easier to view and work on multiple terminal sessions at once.
  • Session Sharing: You can also collaborate on a single session by sharing the terminal window.
  • Customization: It is so extensive and can be customized to suit your preferences. There are many customizations such as keybindings, status bar, change colours etc.
  • Session Persistence: It retains the current state of the terminal sessions even when closed and reopened. This can be vital for the easy resumption of tasks.
  • Detachable and Attachable: The sessions can be detached and later reattached to the terminal session. This makes it easier to switch between different terminal sessions.
  • Scriptable and Automatable: It can be controlled and automated using scripts and other external tools.
  • Remote Access: it allows you to connect to a Tmxu session on a remote machine. You can manage and control the terminal sessions remotely.

Join me in this guide as we learn the proper way to customize Tmux on Linux and macOS.

Install Tmux on your System

Before we customize it, we need to ensure that Tmux has been installed on the Linux or macOS system. This can be done using the commands below:

##On Ubuntu and Debian
sudo apt update
sudo apt install tmux

##On CentOS and Fedora
sudo yum install tmux

##On Rhel 8
sudo yum install http://galaxy4.net/repo/galaxy4-release-8-current.noarch.rpm
sudo yum install tmux

##On OpenSUSE
zypper install tmux

##on Arch Linux
pacman -S tmux

##On MacOS
brew install tmux

2. Customize Tmux on Linux and macOS

Once installed, Tmux can then be customized to suit your preference. There are so many things we can customize here. By default, Tmux stores its configuration file in ~/.tmux.conf directory. If you have an existing config, take a backup before we proceed with this customization.

Ensure that git is installed before we proceed to clone the sample config below:

cd
git clone https://github.com/gpakosz/.tmux.git

Once clones, create a symbolic link to ~/.tmux.conf:

ln -s -f .tmux/.tmux.conf
cp .tmux/.tmux.conf.local .

In the config, there are several configs defined. This includes:

  • SSH/Mosh aware username and hostname status line information
  • mouse mode toggle with <prefix> m
  • uptime status line information
  • visual theme inspired by Powerline
  • optional highlight of the focused pane
  • laptop battery status line information
  • SSH/Mosh aware split pane (reconnects to remote server)
  • support for 4-digit hexadecimal Unicode characters
  • copy to OS clipboard (needs reattach-to-user-namespace on macOS, xselxclip, or wl-copy on Linux)
  • configurable new windows and panes behaviour (optionally retain current path)

Key bindings

There are also several keybindings in the config. The defined prefix combo for Tmux Keybinding is:

  • Default prefix C-b.
  • Secondary prefix C-a

The <prefix> means you have to either hit Ctrl + a or Ctrl + b. For example, if you have the keybinding as <prefix> c means you have to hit Ctrl + a or Ctrl + b followed by c.

The keybindings in the config are:

  • <prefix> e opens the .local customization file copy with the editor defined by the $EDITOR environment variable (defaults to vim when empty)
  • <prefix> r reloads the configuration
  • <prefix> Tab brings you to the last active window
  • <prefix> < and <prefix> > let you swap panes
  • C-l clears both the screen and the Tmux history
  • <prefix> C-c creates a new session
  • <prefix> b lists the paste-buffers
  • <prefix> - splits the current pane vertically
  • <prefix> _ splits the current pane horizontally
  • <prefix> C-h and <prefix> C-l let you navigate windows (default <prefix> n and <prefix> p are unbound)
  • <prefix> + maximizes the current pane to a new window
  • <prefix> h<prefix> j<prefix> k and <prefix> l let you navigate panes ala Vim
  • <prefix> H<prefix> J<prefix> K<prefix> L let you resize panes
  • <prefix> F launches Facebook PathPicker (if available)
  • <prefix> m toggles mouse mode on or off
  • <prefix> Enter enters copy-mode
  • <prefix> p pastes from the top paste-buffer
  • <prefix> P lets you choose the paste buffer to paste from
  • <prefix> U launches Urlview (if available)
  • <prefix> C-f lets you switch to another session by name

In case of any alterations to this sample config, you should refer to the  sample .local customization file. In the below image, I have used <prefix> - to split the current pane vertically and <prefix> _ to split the current pane horizontally

Proper Way To Customize Tmux on Linux and macOS

Enabling the Powerline look

The Powerline was developed as a status-line plugin for Vim. This is a nifty look based on several symbols for your shell. There are several options that can be used to implement the symbols. These include:

You can also modify the .local file by pressing <prefix> e and making the below adjustments. Esure that vim has been installed before you proceed.

tmux_conf_theme_left_separator_main='\uE0B0'
tmux_conf_theme_left_separator_sub='\uE0B1'
tmux_conf_theme_right_separator_main='\uE0B2'
tmux_conf_theme_right_separator_sub='\uE0B3'

Configure the Status Line

To configure the status line, you can modify your .local customization file. To modify it, use <prefix> e and modify the below variables as desired:

  • #{battery_bar}: horizontal battery charge bar
  • #{battery_percentage}: battery percentage
  • #{battery_status}: is battery charging or discharging?
  • #{battery_vbar}: vertical battery charge bar
  • #{circled_session_name}: circled session number, up to 20
  • #{hostname}: SSH/Mosh aware hostname information
  • #{hostname_ssh}: SSH/Mosh aware hostname information, blank when not connected to a remote server through SSH/Mosh
  • #{loadavg}: load average
  • #{pairing}: is session attached to more than one client?
  • #{prefix}: is prefix being depressed?
  • #{root}: is current user root?
  • #{synchronized}: are the panes synchronized?
  • #{uptime_y}: uptime years
  • #{uptime_d}: uptime days, modulo 365 when #{uptime_y} is used
  • #{uptime_h}: uptime hours
  • #{uptime_m}: uptime minutes
  • #{uptime_s}: uptime seconds
  • #{username}: SSH/Mosh aware username information
  • #{username_ssh}: SSH aware username information, blank when not connected to a remote server through SSH/Mosh

Enable Auto Start

After the adjustments have been made, you can set Tmux to run automatically when a terminal is lauched. To achieve that, modify your bashrc as shown.

cat <<EOF >> ~/.bashrc
[ -z "$TMUX"  ] && { tmux attach || exec tmux new-session && exit;}
EOF

Source the profile:

source ~/.bashrc

Now you will have Tmux start when a terminal is lauched. For example through SSH:

Proper Way To Customize Tmux on Linux and macOS 1

There are many other customizations you can make, to do so, just modify the .local file using <prefix> e.

Verdict

This guide has provided the easiest and proper way to customize Tmux on Linux and macOS. Now you can have an appealing terminal. Fee free to share your experience in the comments below.

Recommended Linux Books  to read:

See more:

Related Articles

macos Install and Configure Kitty Terminal Emulator on Linux | macOS macos Install Alacritty Terminal Emulator on Linux, macOS and Windows macos How To Install and use FreeTube on Linux / macOS Arch Linux Install yakyak – Desktop chat client for Google Hangouts on Linux / macOS / Windows

Press ESC to close