A not out-of-box but more flexible and powerful tmux plugin to
customize tmux status bar. The biggest difference between other similar plugins
is it doesn't provide any variables to control status bar like other plugins,
but provides some functions to ~/.config/tmux/tmux.conf
and make it
possible to cooperate with other tmux plugin, which let users to control tmux
by a more "tmux" method.
- powerline: use
~/.config/powerline/config.json
to configure - tmux-powerline: use
.tmux-powerlinerc
, which is a bash script, to configure - There are many tmux themes,
which provide some variables to allow user to customize separators, colors and
some less attributions on
~/.config/tmux/tmux.conf
by tmux script. - Oh My Tmux!: it is not a tmux plugin, it is a tmux configuration, which contains some variables to configure tmux status bar like tmux themes. It is too large and perhaps separate some functions of its code to many different tmux plugins can be better.
~/.config/tmux/tmux.conf
:
# [XXX] can be ignored
set -g status-left "#{status-left:[[format;][fg_color,bg_color,text;][sep];]...}"
set -g status-right "#{status-right:[[format;][sep;][fg_color,bg_color,text];]...}"
set -g window-status-current-format "#{window-status-current-format-left:[format;][sep;]fg_color,bg_color,text;[sep]}"
# or
set -g window-status-current-format "#{window-status-current-format-right:[format;][sep;]fg_color,bg_color,text;[sep]}"
For example, in ~/.config/tmux/tmux.conf
:
set -g status-left "#{status-left:%s;#fffafa,black,a;;%s ;blue,green,b;; %s ;red,colour04,c;}"
It will be translated to:
$ tmux show -gqv status-left
#[fg=#fffafa,bg=black]a#[fg=black,bg=green]#[fg=blue]b #[fg=green,bg=colour04]#[fg=red] c #[fg=colour04,bg=default]
and output:
Yes, this plugin is not out-of-box. You must call this function by yourself. As a reward, you have more freedom to control tmux status line. Let us see a more complex example, how to get the right status line of the first screenshot. The code is copied from my dotfiles:
set -g status-right \
"#{status-right:%s;\
white,colour04,#{prefix_highlight}#[bg=colour04];\
black,yellow,#{pomodoro_status};\
\
black,#9370db,\
#{?#{==:#{bitahub_status_gtx1080ti},},,1080ti #{bitahub_status_gtx1080ti}}\
#{?#{||:#{==:#{bitahub_status_rtx3090},},#{==:#{bitahub_status_gtx1080ti},}},,}\
#{?#{==:#{bitahub_status_rtx3090},},,3090 #{bitahub_status_rtx3090}};\
\
white,#b34a47,\
#{?#{||:#{==:#{battery_percentage},0%},#{==:#{battery_percentage},}},\
#{net_speed},#{battery_icon_status}#{battery_remain}\
#{battery_color_status_fg}#[bg=#b34a47]\
#{battery_icon_charge}#{battery_percentage}};\
\
black,#87ceeb,%F%H:%M%a}"
We can see there are 5 sections. %s
strips the default around white spaces to
save length.
- Display if prefix key is pressed. Provided by tmux-prefix-highlight.
- A pomodoro timer. Provided by tmux-pomodoro-plus.
- Display number of GPU servers of my laboratory. Provided by
my plugin. It can be split to
three parts:
#{?#{==:#{bitahub_status_gtx1080ti},},,1080ti #{bitahub_status_gtx1080ti}}
: if#{bitahub_status_gtx1080ti}
get empty result, which means network is offline. We don't display1080ti
to save length.#{?#{||:#{==:#{bitahub_status_rtx3090},},#{==:#{bitahub_status_gtx1080ti},}},,}
: when only both#{bitahub_status_gtx1080ti}
and#{bitahub_status_rtx3090}
are not empty, a separator will be displayed.- Same as first part.
- Display battery percentage and charge time or net speed. That is because for desktop, which doesn't have a battery. So we display battery information for the laptop and net speed for the desktop. The code is similar to above section. Provided by tmux-net-speed and tmux-battery.
- Display date and time.
I create this plugin for two purposes:
- This plugin don't attach any other plugin which display useful information. You can search it in awesome-tmux and tmux-plugins/list. In fact, some IDE-like tmux plugin attach many parts to display some information, which are not general -- other tmux plugin cannot use them! Imitate Unix philosophy, every tmux plugin should do one thing, and do best. This plugin just provides some functions to control tmux status bar. Display useful information? That are other plugin's jobs.
- This plugin use tmux script which is the language
~/.config/tmux/tmux.conf
uses to configure. I knowpowerline
s python,tmux-powerline
's bash is more advanced language, However, tmux script is more easy to call other tmux plugins, which cannot be ignored.
BTW, at the first screenshot, 0, 1, 2, ... is displayed to ⓪
①
, ②
, which
is done by my another plugin. Don't
forget one plugin do one thing. 😄 If you want to use similar style of
prompt/status bar for other programs (gdb, lftp, ...), Here is
an incomplete list.
set -g @plugin Freed-Wu/tmux-status-bar
run ~/.config/tmux/plugins/tpm/tpm
cpan tmux-status-bar
run-shell tmux-status-bar