Home Terminal Tuts How to change themes on Tmux

How to change themes on Tmux

by Abraham
changing themes tmux

The ability to customize Tmux is one of its most notable features. You may modify the themes in Tmux to ensure that you work in an environment that suits you. This article guide will show you how to change your theme in Tmux. Let us go over the steps.

Tip: Check out our in-depth article guide on installing and using Tmux on Linux.

How to change themes on Tmux

Tmux uses prefixes commonly referred to as ‘keyboard shortcuts’ plus various keys to execute different functions depending on the key combinations.

When you look at the Tmux default appearance, it is not appealing at all. Therefore, this section comes in handy when you plan to customize it to your preferred look and feel. In Tmux, you have the laxity to customize almost everything, including the status bar, colors, style, look and feel of your Tmux application. We shall also be showing you how you can toggle between light and dark mode themes on your Tmux application. Therefore, to accomplish all these configurations, follow the simple step-by-step guide provided herein:

Note: It is advised to split your configuration files into separate files to avoid conflicts between the two files. The first config file is the usual (~/.tmux.conf) and (~/.tmux.ThemeName.theme) that contain all the themes to be used by your Tmux application. Separating these files will make it easy for you to switch between different themes without conflicting with the configuration files.

To load a theme that depends solely on the environmental variable, append the following lines to your main Tmux configuration file:

run-shell “tmux source-file ~/.tmux.\${TMUX_THEME:-default}.theme”
append your main tmux.conf file

Append your main tmux.conf file

From the above line of code, the environment variable $ TMUX_THEME is the basis for the dynamic call to the file holding the tmux theme. When an environment variable is empty, tmux automatically loads a generic theme: ~/.tmux.default.theme

Additionally, you may load several themes. With the source file and Tmux, the procedure is simple to complete:

tmux source-file ~/.tumux.THEMENAME.theme

Note: Always change the THEMENAME to the actual name of your theme. If you are unfamiliar and don’t know how to do that, don’t freak out since running the provided commands will do all the magic for you.

Example:

Follow the following steps to install Tmux themes on your Linux OS manually:

Step 1: Clone the repository to your OS by executing the following line of code:

git clone https://github.com/jimeh/tmux-themepack.git ~/.tmux-themepack
clone themepack

Clone theme pack

Step 2: Source your preferred theme to your ~/.tmux.conf file using this command:

 source-file "${HOME}/.tmux-themepack/powerline/default/green.tmuxtheme"
append tmux theme pack

Append tmux theme pack

Note: If you encounter a ‘No such file or directory’ error, remove the quotations marks in the source-file command and rerun it as shown below:

 source-file ${HOME}/.tmux-themepack/powerline/default/green.tmuxtheme
green theme

green theme

Alternatively, you can use the Tmux plugin manager to change themes on your Tmux application. To do so, follow the steps provided below:

Step 1: Add a plugin to the list of TPM plugins contained in your tmux.conf file by appending the following line on your configuration file:

set -g @plugin 'jimeh/tmux-themepack'
add plugin list

Add plugin list

Step 2: Now use  the default prefix (Ctrl + b) followed by ‘I’ to source and fetch the plugins. The plugin should work flawlessly.

Note: To choose which theme loads, set the @themepack option in your tmux.conf file by appending the following lines:

set -g @themepack 'basic' #default
set -g @themepack 'powerline/block/blue'
set -g @themepack 'powerline/block/cyan'
set -g @themepack 'powerline/default/green'
set -g @themepack 'powerline/double/magenta'
choose which themes to load

Choose which themes to load

Finally, if you intend to do away with the Tmux theme, then all you need to do is remove the tmux.conf file by executing the following line of code in your terminal:

rm ~/.tmux.conf

The above command will remove the Tmux configuration file containing the theme you added to your Tmux application. However, it is important to clear the air by noting that whenever you remove the tmux.conf file, then all your configurations and customizations will be removed. This includes keybinds, custom visuals, themes, and many more. Therefore, to avoid this error, open the tmux.conf file and delete the theme line and save your Tmux config file. This will only delete the theme preserving all other customizations and configurations.

How to toggle between light and dark mode themes

The window-style setting in Tmux allows you to choose between light-on-dark and dark-on-light terminal themes by altering the foreground and background colors that are used by default for windows:

# Change to the light mode 

tmux set window-style 'fg=#171421,bg=#ffffff'
set to light mode

Set to light mode

# Change to the dark mode

tmux set window-style 'fg=#d0cfcc,bg=#171421'
set to dark mode

Set to dark mode

Alternatively, instead of running this command from the terminal, you can customize your shell script as follows:

#!/usr/bin/env sh

# Toggle between light and dark mode themes.

set -e

default_window_style='fg=#d0cfcc,bg=#171421'

alternate_window_style='fg=#171421,bg=#ffffff'

current_window_style=$(tmux show -Av window-style)

case $current_window_style in

    $default_window_style|'default')

        # Change to the alternate window style.

        tmux set window-style $alternate_window_style

        ;;

    *)

        # Change back to the default window style.

        tmux set window-style $default_window_style

        ;;

esac
create script

Create script

Once done, save the script as ~/.tmux/bin/toggle-theme. Now make the script executable by running the following line of code:

chmod u+x ~/.tmux/bin/toggle-theme
make file executable

make file executable

After that, we can now comfortably toggle between the light and dark mode themes using the following command:

~/.tmux/bin/toggle-theme

To take it even a notch higher, we shall bind a keyboard shortcut to aid toggle between the light and dark mode themes. To do so, launch your tmux.conf file using the following command:

sudo nano ~/.tmux.conf

Now append the following line and save and exit the nano editor using the following keyboard combinations (Ctrl + X) followed by ‘y’

Reload the tmux.conf file by executing the following line of code:

tmux source-file ~/.tmux.conf
reload tmux config file

Reload the Tmux config file

Alternatively, if you have a reload config shortcut, you can use it to reload the file.

Use the following shortcut to toggle between the light and dark mode themes.

'Ctrl + b' followed by 'Shift + T'

In the above line, ‘Ctrl + b‘ is the default Tmux prefix while ‘Shift + T‘ is the keyboard combination to write an uppercase ‘T,’ our preceding key.

How to change the pane border style

Now that you know how to toggle between the dark and light mode themes, you might want to take things a notch higher and append the script to change other options, such as the pane border style. This is actually changing the colors of your pane borders. The current script we used to alter the dark and light modes changes the default background and foreground of the current window, alongside all other panes. Now to change the status line colors that appear against the dark and light backgrounds, you will need to add the following lines to the tmux.conf file:

Launch the file by executing the following line of code:

sudo nano ~/.tmux.conf
start tmux.conf file

Start tmux.conf file

Now append the following lines to your tmux.conf file:

set -g status-style 'fg=#d0cfcc,bg=#171421'

set -g window-status-current-style 'bg=default,reverse'
customize pane border style

Customize pane border style

Note: You can also use the -g parameter to change the colors of the windows across all sessions or the -p parameter to change the colors of the current pane only:

# Change windows colors across all sessions.


tmux set -g window-style 'fg=#171421,bg=#ffffff'
Change windows colors across all sessions

Change windows colors across all sessions

change color of all border sessions

Change color of all border sessions

# Only change the colors of the current pane


tmux set -p window-style 'fg=#171421,bg=#ffffff'
change colors of active pane only

Change colors of the active pane only

That’s how you can change themes on your Tmux application.

Alternative tip:

It is much easier to configure your tmux.conf file to enable you easily access the widely used actions. For instance, my main tmux.conf file contains a reload shortcut that aids in reloading the Tmux configuration quickly. Using that shortcut, you can quickly but effectively change to the current theme. For instance, the following command creates a reload shortcut that can be accessed by using the default prefix followed by ‘r‘ instead of loading a terminal to run a reload command:

bind r source-file ~/.tmux.conf
create config reload shortcut

Create config reload shortcut

Conclusion

This brief guide covered how you can configure themes on your Tmux application. If you are new to Tmux, changing the theme to your preference will play a huge role in aiding you to grasp and understand this application more, as the default theme seems more complex. Therefore, we hope you found this guide quite useful. If yes, please write to us via the message board below, and we will be glad to respond to your feedback and concerns.

You may also like

Leave a Comment

fl_logo_v3_footer

ENHANCE YOUR LINUX EXPERIENCE.



FOSS Linux is a leading resource for Linux enthusiasts and professionals alike. With a focus on providing the best Linux tutorials, open-source apps, news, and reviews written by team of expert authors. FOSS Linux is the go-to source for all things Linux.

Whether you’re a beginner or an experienced user, FOSS Linux has something for everyone.

Follow Us

Subscribe

©2016-2023 FOSS LINUX

A PART OF VIBRANT LEAF MEDIA COMPANY.

ALL RIGHTS RESERVED.

“Linux” is the registered trademark by Linus Torvalds in the U.S. and other countries.