Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I am attempting to create a tmux status bar which shows three timezones: US Eastern Time :: UTC :: Central European Time. Using the TZ environment variable makes the date command show the time in a given timezone.

I was attempting to do so with this tmux.conf setting:

set -g status-right "#[fg=white]#S #I:#P #[fg=yellow]:: %d %b %Y #[fg=green]:: #(TZ=America/New_York date +%H:%M) :: #(date -u +%H:%M) UTC :: #(TZ=Europe/Belgrade date +%H:%M)"

However, passing TZ=foo does not work inside of #(…). (I get the server date instead of what I expected). Any suggestions?

share|improve this question

2 Answers 2

up vote 5 down vote accepted

Tmux expands time formats with strftime in status-left and status-right before it expands #(…) and other sharp escape sequences. So %H:%M is expanded to the local time first, and date runs with an argument that is already numeric.

Double the percent signs.

set -g status-right "#[fg=white]#S #I:#P #[fg=yellow]:: %d %b %Y #[fg=green]:: #(TZ=America/New_York date +%%H:%%M) :: #(TZ=UTC date -u +%%H:%%M) UTC :: #(TZ=Europe/Belgrade date +%%H:%%M)"

share|improve this answer
    
Thank you!!! That was exactly the problem... :) –  Excalibur Feb 19 at 17:34

I am not familiar with tmux but I guess the problem is that #() does not work the same way like $() in the shell.

The problem may be solved by forcing the use of a shell:

#(bash -c 'TZ=Europe/Belgrade date +%H:%M')
share|improve this answer
    
Unfortunately this doesn't work (in tmux 1.6, Gentoo). It's still printing the UTC date. –  Excalibur Feb 18 at 21:59
    
@Excalibur Quite strange. Try creating a wrapperscript (with TZ=Europe/Belgrade date +%H:%M) and #(/path/to/wrapperscript) –  Hauke Laging Feb 18 at 22:19
    
Yeah, that solution did occur to me. Although since this tmux.conf is set dynamically using Chef, I'm hesitant to add any external dependencies. Perhaps I should file an issue with tmux. Thanks though! –  Excalibur Feb 18 at 23:47

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.