Skip to content

Freed-Wu/tmux-status-bar

Repository files navigation

tmux-status-bar

pre-commit.ci status github/workflow codecov DeepSource

github/downloads github/downloads/latest github/issues github/issues-closed github/issues-pr github/issues-pr-closed github/discussions github/milestones github/forks github/stars github/watchers github/contributors github/commit-activity github/last-commit github/release-date

github/license github/languages github/languages/top github/directory-file-count github/code-size github/repo-size github/v

cpan/v

screenshot

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.

Similar Projects

  • 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.

Usage

~/.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:

example

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.

  1. Display if prefix key is pressed. Provided by tmux-prefix-highlight.
  2. A pomodoro timer. Provided by tmux-pomodoro-plus.
  3. Display number of GPU servers of my laboratory. Provided by my plugin. It can be split to three parts:
    1. #{?#{==:#{bitahub_status_gtx1080ti},},,1080ti #{bitahub_status_gtx1080ti}}: if #{bitahub_status_gtx1080ti} get empty result, which means network is offline. We don't display 1080ti to save length.
    2. #{?#{||:#{==:#{bitahub_status_rtx3090},},#{==:#{bitahub_status_gtx1080ti},}},,}: when only both #{bitahub_status_gtx1080ti} and #{bitahub_status_rtx3090} are not empty, a separator will be displayed.
    3. Same as first part.
  4. 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.
  5. Display date and time.

Motivations

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 know powerlines 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.

Install

set -g @plugin Freed-Wu/tmux-status-bar
run ~/.config/tmux/plugins/tpm/tpm
cpan tmux-status-bar
run-shell tmux-status-bar