Home Terminal Tuts Customizing the Tmux status bar in Linux

Customizing the Tmux status bar in Linux

We will cover various aspects of the configuration process, including changing colors, adding custom text, and displaying system information.

by Abraham
customizing the tmux status bar in linux

Tmux is a popular terminal multiplexer that allows users to create multiple terminal sessions within a single window. One of the most useful features of Tmux is its status bar, which displays various information such as the current session, time, and battery status. However, the default status bar may not always meet your needs, so you may want to customize it.

This article will explore how to customize the Tmux status bar in detail. We will cover the different components of the status bar, how to modify them, and provide examples of customized status bars. By the end of this tutorial guide, you will have a comprehensive understanding of how to customize the Tmux status bar to your liking.

Understanding the Tmux status bar

The Tmux status bar is a line of information that appears at the bottom of the terminal window. It contains various components displaying information such as the current session, hostname, time, battery status, etc. By default, the status bar is displayed in white text on a black background. However, you can customize the status bar’s color, position, and content.

The status bar consists of three main parts: the left section, the center section, and the right section. The left section displays information about the current session, such as its name and number. The center section shows information about the current window, such as its name and whether it is active or not—the right section displays system information, such as the time, battery status, and hostname.

Customizing the Tmux status bar

To customize the Tmux status bar, modify the configuration file at ~/.tmux.conf. If you do not possess a configuration file, you can create one by running the following command in your terminal:

touch ~/.tmux.conf
create configuration file

Create configuration file

Once you have created the configuration file, you can open it in your text editor and modify it.

Changing the color of the status bar

By default, the status bar is displayed in white text on a black background. However, you can change the color of the status bar to match your preferences. To change the color of the status bar, you need to modify the status-style option in your configuration file.

set-option -g status-style "bg=black,fg=gold"
change status bar color

Change the status bar color

In this example, we set the background color to black and the foreground color to white.

change status bar to black background and white foreground

Change the status bar to black background and white foreground

You can use any color that your terminal emulator supports. You can also use hexadecimal color codes if you prefer.

Customizing the status bar  – left section

The left section of the status bar displays information about the current session. By default, it shows the session name and number. However, you can customize it to display other information, such as the current directory or the number of windows in the session.

To customize the left section, modify the status-left option in your configuration file.

set-option -g status-left "Session #S (#{window_index} windows) "
customize status bar left section

Customize the status bar left section

In this example, we added the number of windows in the session to the left section. You can customize it to display any information that you find helpful. For instance, you can see our tmux window showing session 5 below:

session 5

Session 5

Customizing the status bar – center section

The center section of the status bar displays information about the current window. By default, it shows the window name and whether it is active or not. However, you can customize it to display other information, such as the current pane’s title or the current Git branch.

To customize the center section, modify the status-right option in your configuration file.

set-option -g status-right "#[fg=green]#I:#W#F "
customize status bar right section

Customize the status bar right section

Here’s an example configuration that sets the center section to display the current window index and name:

set -g status-left ''

set -g status-right '#[fg=white]#I:#W#[default]'
customize center section

Customize center section

This configuration uses the #I and #W format strings to display the window index and name, respectively. The fg=white option sets the foreground color to white, and the default option sets the background color to the default value.

window index and name on a white background

Window index and name on a white background

You can customize the center section further by adding additional format strings or options. For example, you could include the current pane’s title or active program, or set custom colors or formatting.

Here’s an example configuration that includes the current pane’s title:

set -g status-left ''

set -g status-right '#[fg=white]#I:#W #[fg=yellow]#T#[default]'
show title pane in red

Show title pane in red

This configuration uses the #T format string to display the current pane’s title, and sets the foreground color to red. You can experiment with different format strings and colors to find a configuration that works best for you.

customize title pane to display in red

Customize title pane to display in red

Customizing the status bar  – right section

The right section of the tmux status bar is typically used to display system information such as the date and time, system load, or battery status. By default, it shows the time and date. You can customize this section by modifying the status-right option in your tmux.conf configuration file.

Here’s an example configuration that sets the right section to display the current date and time:

set -g status-right '#[fg=white]%Y-%m-%d %H:%M#[default]'
set status right

Set status right

This configuration uses the %Y-%m-%d %H:%M format string to display the current date and time in the YYYY-MM-DD HH:MM format. The fg=white option sets the foreground color to white, and the default option sets the background color to the default value.

display current date and time

Display current date and time

You can customize the right section further by adding additional format strings or options. For example, you could include system load or battery status by using the appropriate format strings.

Here’s an example configuration that includes system load:

set -g status-right '#[fg=white]%Y-%m-%d %H:%M #[fg=yellow]%L, %B#[default]'

This configuration uses the %L format string to display the current system load, and the %B format string to display the current battery status. The fg=yellow option sets the foreground color to yellow. Again, you can experiment with different format strings and colors to find a configuration that works best for you.

display system load and set foreground color to yellow

Display system load and set foreground color to yellow

How to change the clock display style in Tmux

Tmux is a powerful terminal multiplexer that can enhance productivity and streamline workflow. One of its valuable features is the ability to display the current time in the status bar. By default, Tmux displays the time in the hours and minutes format. However, you can customize the display style of the clock to show the time in different formats, such as 12-hour or 24-hour time, and to display additional information, such as the date or day of the week. Here we will explore how to change the display style of the clock in Tmux.

Customizing the clock style

To customize the clock style in Tmux, you must modify the status-right option in your configuration file. The status-right option controls the contents of the status bar’s right side, where the clock is displayed by default.

Here’s an example of how to customize the clock style to display the time in a 12-hour format with AM/PM indicator:

set-option -g status-right "%I:%M %p"
customize clock appearance

Customize clock appearance

In this example, %I displays the hour in 12-hour format, %M displays the minutes, and %p displays the AM/PM indicator. You can modify this format to display the time in any style you prefer.

clock appearance

Clock appearance

Here’s another example that displays the time in 24-hour format with seconds:

set-option -g status-right "%H:%M:%S"
24 hour format

24-hour format

In this example, %H displays the hour in 24-hour format, %M displays the minutes, and %S displays the seconds. Again, you can modify this format to display the time in any style you prefer.

24 hour clock appearance with seconds

24-hour clock appearance with seconds

Displaying additional information

In addition to customizing the clock style, you can display additional information in the status bar, such as the date or day of the week.

Here’s an example that displays the time, date, and day of the week:

set-option -g status-right "%a %d %b %I:%M %p"
display additional information

Display additional information

In this example, %a displays the abbreviated day of the week (e.g., Mon), %d displays the day of the month, %b displays the abbreviated month (e.g., Jan), and %p displays the AM/PM indicator. Again, you can modify this format to display the information that you find helpful.

clock displaying additional info

Clock displaying additional info

Customizing the clock display style in Tmux can help you personalize your terminal environment and display the information you need in a way that is easy to read and understand. Modifying your Tmux configuration file allows you to create a customized status bar that meets your needs and preferences.

Adding custom icons and colors

In addition to modifying the status bar’s text, you can add custom icons and colors to make it more visually appealing. You can use Unicode characters or ASCII art to create custom icons. For example, you can use the following code to add a battery icon and percentage to the tmux status bar. To do so, follow these steps:

  1. Install a patched font that includes a battery icon. You can find many patched fonts with icon sets on GitHub, such as Nerd Fonts.
  2. Add the following lines to your .tmux.conf file:
# Set status bar style
set -g status-style bg=black,fg=white

# Set left side of status bar
set -g status-left ""
set -g status-left-length 30
set -g status-left "#(echo '\uf240') #(/usr/bin/pmset -g batt | awk '{printf \"%s%%\", $2}' | sed 's/;//g') "

# Set right side of status bar
set -g status-right ""
set -g status-right-length 60
set -g status-right "#(echo 'ICON2') #[fg=green]%d-%m-%Y %H:%M "
battery icon and status configuration

Battery Icon and status configuration

The battery icon character \uf240 is specific to the font you are using, so you may need to replace it with the appropriate character for your font. The command pmset -g batt retrieves the battery information on macOS. If you are using a different operating system, you may need to use a different command to retrieve battery information. For instance, on Linux we use the ‘upower‘ command as seen in the configuration above.

Reload your .tmux.conf file by running tmux source-file ~/.tmux.conf.

Your custom battery icon and percentage should now appear on the left side of the status bar.

add battery icon and status indicator

Add battery icon and status indicator

Note that the battery percentage may not update in real-time, so you may need to refresh the status bar periodically to see the current percentage. You can do this by pressing the tmux prefix key (usually Ctrl-b) followed by the r key.

Add custom colors to the status bar using the #[fg=color] and #[bg=color] options. For example, you can use the following code to add a blue background to the status bar:

set-option -g status-style "bg=blue,fg=white"
blue backgound

Blue background

How to move the window list in the Tmux status bar

As previously said, the status bar is one of the most vital Tmux features, as it displays information about your active session and windows. By default, the window list in the status bar is located on the left side, but you may want to move it to a different location. Therefore, I will elaborate on moving the window list in the Tmux status bar to the right side.

Moving the window list to the right side

To move the window list to the right side of the status bar, you need to modify the status-left option in your Tmux configuration file. By default, the status-left option displays information on the left side of the status bar, including the window list. However, you can customize this option to move the window list to a different location.

Here’s an example of how to move the window list to the right side of the status bar:

set-option -g status-left ''

set-option -g status-right '#[align=right]#{?client_prefix,#[fg=green]Prefix #[fg=white],}#{pane_title}'
move windows list to the right side

Move the windows list to the right side

In this example, we set the status-left option to an empty string, which removes any content from the left side of the status bar. We then set the status-right option to display the window list on the right side using the #[align=right] directive. This directive aligns the content to the right side of the status bar.

move content to the right side

Move the content to the right side

You may also notice that we included additional content in the status-right option, including the pane title and the client prefix. You can customize this content to display the information that you find helpful.

Moving the window list to the right side of the status bar in Tmux can help you organize your terminal sessions and windows more conveniently and efficiently. By modifying the status-left and status-right options in your Tmux configuration file, you can customize the status bar layout to meet your needs and preferences.

Reloading a Tmux configuration file

When you make changes to your Tmux configuration file, you need to reload the file for the changes to take effect. Reloading the configuration file is simple and can be done within a running Tmux session.

Here are the steps to reload the Tmux config file:

  • Open a Tmux session by running the tmux command in your terminal.
  • Press Ctrl + b followed by : to enter the Tmux command prompt.
  • Type source-file ~/.tmux.conf and press Enter to reload the configuration file.
    reload tmux config file

    Reload the tmux config file

    This assumes that your Tmux configuration file is located in the default location of your home directory with the filename .tmux.conf. If your configuration file is located elsewhere or has a different name, replace ~/.tmux.conf with the correct path and filename.

  • Once you run the source-file command, Tmux will reload the configuration file and apply any changes you have made. You should now see the updated settings reflected in your Tmux session.

It’s important to note that reloading the configuration file will not affect running Tmux sessions or windows. Any changes you make to the configuration file will only take effect in new Tmux sessions or windows. I hope you can now customize the Tmux Status Bar with the aid of this article guide.

Conclusion

Customizing the Tmux status bar can help you make the most of your terminal sessions by displaying relevant information in a way that is easy to read and visually appealing. In this article, we explored how to customize the different sections of the status bar, how to change the color of the status bar, and how to add custom icons and colors. Modifying your Tmux configuration file allows you to create a customized status bar that meets your needs and preferences. We hope this article has provided you with a comprehensive understanding of how to customize the Tmux status bar and that you find it useful in your terminal workflow. Thank you for reading!

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.