trgyrq
Last Updated: May 06, 2017
·
10.89K
· hauleth
Me

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

Say Thanks
Respond

12 Responses
Add your response

11707
58abfe08f2065deecf69e838eeac3dc0

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

over 1 year ago ·
11708
Me

@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 ·
11713
58abfe08f2065deecf69e838eeac3dc0

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

over 1 year ago ·
11714
Me
over 1 year ago ·
11715
58abfe08f2065deecf69e838eeac3dc0

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

over 1 year ago ·
11716
58abfe08f2065deecf69e838eeac3dc0

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

over 1 year ago ·
11720
06237052745686cba3fcb34d056d3cad

nice idea :D

over 1 year ago ·
11726
F93e90d4db9dc0eb3b5681c6fccfa0e2

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 ·
11734
Me

@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 ·
11763
Me
over 1 year ago ·
12214
5e47e75af9d584936f6b4be3520c75d7

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 ·
12240
Me

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

over 1 year ago ·
Filed Under