Creating a TMUX Status Bar Widget
Intro
TMUX is a terminal multiplexer, meaning TMUX can split your terminal into many panes or tabs. You can detach from TMUX sessions and reattach in different terminal sessions. TMUX has a status bar at the bottom of the terminal window. The status bar is customizable and runs custom programs. In this article, I will walk through how to set up and run custom TMUX status bar scripts that I will refer to as widgets.
Prerequisites:
- TMUX installed.
- Some knowledge of TMUX will be helpful.
Planning the Widget Script
The first step when creating your widget is to plan how you want it to work. We will need the code to respond with text. This response is what we will display in the status bar.
TMUX allows you to run any bash command in the status bar, so the widget can run any command line script. This example will use Bash.
I will use a simple bash example to return a random number every second. Brilliant, right?
while echo $RANDOM; do sleep 1; done
Implementing the Script as a Widget
In the home directory ~/
a TMUX configuration file is available .tmux.conf
.
In the configuration file there’s is a left-side status-left
and a right-side status-right
. In this example I will place it on the left side without custom styling.
set -g status-left '#(while echo $RANDOM; do sleep 1; done)'
Notice the need to loop through the script. This is to update the response.
Implementing Separate Code as a Widget
To make more complicated widgets for the TMUX status bar use a script file. A script file is a way to use a programming language of choice to make complex widgets.
Here is an example of a weather script I have created with NODEjs.
set -g status-right '#[fg=colour233,bg=colour117,bold] #(node ~/scripts/tmux/weather.js) #[bg=colour234,bold] #[fg=colour233,bg=colour245,bold] %d/%m - %H:%M '
Here is an example of the weather script running in my TMUX status bar.
Conclusion/Key Takeaways
In conclusion, we now understand that TMUX can run custom scripts. Here are three main takeaways.
3 takeaways:
- TMUX can run custom scripts or programs.
- The custom scripts can provide meaningful information when using TMUX.
- The custom scripts in TMUX can use any language that can run in the terminal.
The examples provided are simple, but it’s a great start to building custom information into TMUX. Have fun, and make your TMUX even more powerful!
References
TMUX Repository
About the author
Written by Nicholas Diesslin Pizza acrobat 🍕, typographer, gardener, bicyclist, juggler, senior developer, web designer, all around whittler of the web.
Follow Nick on Twitter!