Multiple Time Zones in tmux Status Bar

2 minute read

I’m currently working remotely and part-time from London with the rest of my team in San Francisco. I don’t enjoy converting between time zones and since I spend most my time within tmux, I modified my status bar to include multiple time zones.

To do this, I use the unix date utility and set the TZ (time zone) environment variable before each date call. Unfortunately, when tmux executes these commands, the time zone environment variables are expanded and both times printed are within the same time zone.

Solution 1

Create another script to be called by tmux. A bit hacky.

~/.tmux.conf
# ...
set -g status-interval 1
set -g status-right "#(~/ldate.sh 'US/Pacific') #(~/ldate.sh 'Europe/London')"
set -g status-right-length 60
# ...
~/ldate.sh
#!/bin/bash
echo $(TZ=":$1" date "+%Z %H:%M:%S")

Solution 2

Escape the % characters appropriately within the .tmux.conf file. The status bar will update every status-interval (so make it update every second or so!). We need to escape the % with another % instead of a \ as tmux passes the times through strftime.

~/.tmux.conf
# ...
set -g status-interval 1
set -g status-right
  "#(echo $(TZ=':US/Pacific' date '+%%Z %%H:%%M:%%S'))"
  "#(echo $(TZ=':Europe/London' date '+%%Z %%H:%%M:%%S'))"
set -g status-right-length 60
# ...
background Layer 1