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):
Medium (up to 160 columns):
Big (more than 160 columns):
Written by Łukasz Niemier
Related protips
12 Responses
What are those codes for separators? Seems they didnt make the cut-n-paste.
@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.
hrm.. I guess I'm ignorant.. What is "Powerline" ?
So what are the separators in use in the 2nd script? Same ones?
Ah, got it.. Just had to cut-n-paste again, and the invisible chars here came through properly. Awesome!
nice idea :D
Cool! But could you please put it in a gist.github.com?
Also, there's tmux-powerline, too: https://github.com/erikw/tmux-powerline
@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).
@creaktive - now there is Gist: https://gist.github.com/8127857
Great ! Replaced my old red tmux config with this blue one.
What's this "#{client_width}" shell-command passed on tmux-airline parameter ?
Width of the TMux. It is used to determine which element's should be shown.