Last Updated: September 09, 2019
·
23.56K
· hauleth

Make your TMux status bar responsive

I've recently created simple script that create Powerline-like theme for TMux. See:

#!/bin/sh

LSEP=
LSEPE=
RSEP=
RSEPE=

CLOCK=⌚
CALENDAR=☼
MUSIC=♫

WIDTH=${1}

SMALL=80
MEDIUM=140

if [ "$WIDTH" -gt "$MEDIUM" ]; then
  MPD="#[fg=colour252,bg=default,nobold,noitalics,nounderscore]$RSEP#[fg=colour16,bg=colour252,bold,noitalics,nounderscore] $MUSIC $(mpc current)"
  date_colour='colour252'
fi

if [ "$WIDTH" -ge "$SMALL" ]; then
  UNAME="#[fg=colour252,bg=colour236,nobold,noitalics,nounderscore]$RSEP#[fg=colour16,bg=colour252,bold,noitalics,nounderscore] $(uname -n)"
fi
DATE="#[fg=colour236,bg=${date_colour:-default},nobold,noitalics,nounderscore]$RSEP#[fg=colour247,bg=colour236,nobold,noitalics,nounderscore] $CALENDAR $(date +'%D')"
TIME="#[fg=colour241,bg=colour236,nobold,noitalics,nounderscore]$RSEPE#[fg=colour252,bg=colour236,bold,noitalics,nounderscore] $CLOCK $(date +'%H:%M')"

echo "$MPD $DATE $TIME $UNAME " | sed 's/ *$/ /g'

Usage:

set -g status-fg colour231
set -g status-bg colour234
set -g status-left-length 20
set -g status-left '#[fg=colour16,bg=colour254,bold] #S #[fg=colour254,bg=colour234,nobold]'
set -g status-right '#(eval tmux-airline `tmux display -p "#{client_width}"`)'
set -g status-right-length 150

set -g window-status-format "#[fg=colour244,bg=colour234]#I #[fg=colour240] #[default]#W "
set -g window-status-current-format "#[fg=colour234,bg=colour31]#[fg=colour117,bg=colour31] #I  #[fg=colour231,bold]#W #[fg=colour31,bg=colour234,nobold]"

set-window-option -g window-status-fg colour249
set-window-option -g window-status-activity-attr none
set-window-option -g window-status-bell-attr none
set-window-option -g window-status-activity-fg yellow
set-window-option -g window-status-bell-fg red

Remember to set status-interval to 1.

Samples

Small window (up to 80 columns):
Picture

Medium (up to 160 columns):
Picture

Big (more than 160 columns):
Picture

Gist: https://gist.github.com/8127857

12 Responses
Add your response

What are those codes for separators? Seems they didnt make the cut-n-paste.

over 1 year ago ·

@yeraze there are Powerline separators (so you need patched font). Codes are LSEP = 0xEE 0x82 0xB0, RSEP = 0xEE 0x82 0xB2, RSEPE = 0xEE 0x82 0xB3. But you can try other chars.

over 1 year ago ·

hrm.. I guess I'm ignorant.. What is "Powerline" ?

over 1 year ago ·

So what are the separators in use in the 2nd script? Same ones?

over 1 year ago ·

Ah, got it.. Just had to cut-n-paste again, and the invisible chars here came through properly. Awesome!

over 1 year ago ·

nice idea :D

over 1 year ago ·

Cool! But could you please put it in a gist.github.com?
Also, there's tmux-powerline, too: https://github.com/erikw/tmux-powerline

over 1 year ago ·

@creaktive - I would, and I will, but after Christmas. Yeah, but tmux-powerline is now abandoned and Lokaltog version depends on Python. This one is pure shell (I use Airline for Vim).

over 1 year ago ·
over 1 year ago ·

Great ! Replaced my old red tmux config with this blue one.
What's this "#{client_width}" shell-command passed on tmux-airline parameter ?

over 1 year ago ·

Width of the TMux. It is used to determine which element's should be shown.

over 1 year ago ·