状态栏(Status bar)和个性化设置 {#status-bar}¶
在 tmux 界面的下部位置是状态栏,可以进行个性化。它由三个部分组成。左右他们都可以自定义。中间部分为一系列窗口的名字。如下图。
左右的状态 status-left
和 status-right
可以参数设置,通过 configurable 文件 .tmux.conf
,或者想直接命令行修改的方式 $ tmux set-option
。
显示现在的状态栏设置
$ tmux show-options -g | grep status
窗口状态的标记¶
中间的窗口名字列表部分,在这些窗口名字上由一些标识代表不同的信息。整理成下面的表格:
Symbol | Meaning |
---|---|
* | 当前工作窗口 |
- | Marks the last window (previously selected). |
# | Window is monitored and activity has been detected. |
! | A bell has occurred in the window. |
~ | The window has been silent for the monitor-silence interval. |
M | The window contains the marked pane. |
Z | The window's active pane is zoomed. |
小技巧:一个面板(pane)可以被最小化 pane zoomed 通过 Prefix
+ z
,再按一次 Prefix
+ z
或者 按面板的移动组合键,恢复。
日期和时间¶
status-left
和 status-right
部分可以设置日期。
This happens via piping the status templates through format_expand_time
in format.c
, which routes right into strftime(3)
from time.h
.
A full list of variables can be found in the documentation for strftime(3)
. This can be viewed through $ man strftime
on Unix-like systems.
Shell command output¶
You can also call applications, such as tmux-mem-cpu-load, conky, and powerline.
For this example, we’ll use tmux-mem-cpu-load
. This works on Unix-like systems like FreeBSD, Linux distributions, and macOS.
To build from source, you must have CMake and git
, which are available through your package manager. You must have a C++ compiler. On macOS, install Xcode CLI Utilities. You can do this by going to Applications -> Utilities, launching Terminal.app and typing $ xcode-select --install
. macOS can use Homebrew to install the CMake and git package. Major Linux distributions package CMake, clang, and git.
Before this step, you can cd
into any directory you’re ok keeping code in.
$ git clone https://github.com/thewtex/tmux-mem-cpu-load.git
$ cd tmux-mem-cpu-load
$ mkdir ./build
$ cd ./build
$ cmake ..
$ make
# macOS, no sudo required
$ make install
# Linux, BSD will require sudo / root to install
$ sudo make install
If successful, you should see the output below:
[100%] Built target tmux-mem-cpu-load
Install the project...
-- Install configuration: "MinSizeRel"
-- Installing: /usr/local/bin/tmux-mem-cpu-load
You can remove the source code you cloned from the computer. The compiled application is installed.
You can now add #(tmux-mem-cpu-load)
to your status-left
or status-right
option. In the “Dressed up” example below, I
use status-left
and also theme it to be green:
#[fg=green,bg=default,bright]#(tmux-mem-cpu-load)
So to apply it to your theme, you need to double check what you already have. You may have information on there you want to keep.
$ tmux show-option -g status-right
status-right " "#{=21:pane_title}" %H:%M %d-%b-%y"
Copy what you had in response (or change, rearrange as you see fit) then add the
#(tmux-mem-cpu-load)
to it. You can apply the new status line in your current
tmux session via $ tmux set-option -g status-right
:
$ tmux set-option -g status-right '"#{=21:pane_title}" #(tmux-mem-cpu-load) %H:%M %d-%b-%y'
Also, note how I switched out the double quotes on either side of the option with single quotes. This is required, since there are double quotes inside.
You can do this with anything, for instance, try adding uptime
.
This could be done by adding #(uptime)
to your status line. Typically the
output is pretty long, so trim it down by doing something like this:
#(uptime | cut -f 4-5 -d " " | cut -f 1 -d ",")
In the next section, we go into how you can style (color) tmux.
Styling¶
The colors available to tmux are:
black
,red
,green
,yellow
,blue
,magenta
,cyan
,white
.- bright colors, such as
brightred
,brightgreen
,brightyellow
,brightblue
,brightmagenta
,brightcyan
. colour0
throughcolour255
from the 256-color set.default
- hexadecimal RGB code like
#000000
,#FFFFFF
, similar to HTML colors.
Status line¶
You can use [bg=color]
and [fg=color]
to adjust the text color and background within for status line text. This works on status-left
and status-right
.
Let’s say you want to style the background:
Command: $ tmux set-option status-style fg=white,bg=black
In config: status-style fg=white,bg=black
In the examples at the end of the chapter, you will see complete examples of how colors can be used.
Clock styling¶
You can style the color of the tmux clock via:
set-option -g clock-mode-colour white
Reminder: Clock mode can be opened with $ tmux clock-mode
or Prefix
+ t
.
Pressing any key will exit clock mode.
Prompt colors¶
The benefit of wrapping your brain around this styling is you will see it message-command-style
, message style
and so on.
Let’s try this:
$ tmux set-option -ag message-style fg=yellow,blink\; set-option -ag message-style bg=black
Top: default scheme for prompt. Bottom: newly-styled.
Styling while using tmux¶
So, you want to customize your tmux status line before you write the changes to your config file.
Start by grabbing your current status line section you want to edit, for instance:
$ tmux show-options -g status-left
> status-left "[#S] "
$ tmux show-options -g status-right
> status-right " "#{=21:pane_title}" %H:%M %d-%b-%y"
Also, you can try to snip off the variable with | cut -d' ' -f2-
:
$ tmux show-options -g status-left | cut -d' ' -f2-
> "[#S] "
$ tmux show-options -g status-right | cut -d' ' -f2-
> " "#{=21:pane_title}" %H:%M %d-%b-%y"
Then, add the options to your configuration.
To be sure your configuration fully works, you can start it in a different server via tmux -Lrandom
, verify the settings, and close it. This is helpful to make sure your config file isn’t missing any styling info.
Toggling status line¶
The tmux status line can be hidden, as well. Turn it off:
$ tmux set-option status off
And, turn it on:
$ tmux set-option status on
The above is best for scripting, but if you’re binding it to a keyboard shortcut, toggling, or reversing the current option, it can be done via omitting the on/off value:
$ tmux set-option status
Bind toggling status line to Prefix
+ q
:
$ tmux bind-key q set-option status
Example: Default config¶
This is an example of the default config you see if your tmux configuration has no status styling.
status on
status-interval 15
status-justify left
status-keys vi
status-left "[#S] "
status-left-length 10
status-left-style default
status-position bottom
status-right " "#{=21:pane_title}" %H:%M %d-%b-%y"
status-right-length 40
status-right-style default
status-style fg=black,bg=green
Example: Dressed up {#status-bar-example-dressed-up}¶

status on
status-interval 1
status-justify centre
status-keys vi
status-left "#[fg=green]#H #[fg=black]• #[fg=green,bright]#(uname -r | cut -c 1-6)#[default]"
status-left-length 20
status-left-style default
status-position bottom
status-right "#[fg=green,bg=default,bright]#(tmux-mem-cpu-load) #[fg=red,dim,bg=default]#(uptime | cut -f 4-5 -d " " | cut -f 1 -d ",") #[fg=white,bg=default]%a%l:%M:%S %p#[default] #[fg=blue]%Y-%m-%d"
status-right-length 140
status-right-style default
status-style fg=colour136,bg=colour235
# default window title colors
set-window-option -g window-status-fg colour244 # base0
set-window-option -g window-status-bg default
# active window title colors
set-window-option -g window-status-current-fg colour166 # orange
set-window-option -g window-status-current-bg default
Configs can print the output of an application. In this example, tmux-mem-cpu-load is providing system statistics in the right-side section of the status line.
To build tmux-mem-cpu-load, you have to install CMake and have a C++ compiler, like clang or GCC.
On Ubuntu, Debian, and Mint machines, you can do this via $ sudo apt-get install cmake build-essential
. On macOS w/ brew via $ brew install cmake
.
Example: Powerline¶
The most full-featured solution available for tmux status lines is powerline, which heavily utilizes the shell command outputs, not only to give direct system statistics, but also to generate graphical-like styling.
To get the styling to work correctly, special fonts must be installed. The easiest way to use this is to install powerline fonts, a collection of fixed width coder fonts patched to support Wingdings-like symbols.
Installation instructions are on Read the Docs. For a better idea:
$ pip install --user powerline-status psutil
psutil, a required dependency of powerline, is a cross-platform tool to gather system information.
Assure you properly configured python with your PATHs, and try this:
set -g status-interval 2
set -g status-right '#(powerline tmux right)'
Summary¶
Configuring the status line is optional. It can use the output of programs installed on your system to give you specialized information, such as CPU, ram, and I/O usage. By default, you’ll at least have a window list and a clock.
In addition, you can customize the colors of the status line, clock, and prompt. By default, it’s only a green bar with dark text, so take some time to customize yours, if you want, and save it to your configuration.
In the next chapter, we will go into the command line and scripting features of tmux.