在 tmux 状态中设置环境变量 [英] Set environment variable in tmux status
问题描述
我试图在我的 tmux 状态中显示两个不同的时区.我有一个使用 unix date
实用程序的命令,该实用程序在我的 shell 中执行时起作用.
I'm trying to show two different time zones within my tmux status. I have a command that uses the unix date
utility which works when executed within my shell.
echo $(TZ=':US/Pacific' date '+%Z %H:%M:%S' && TZ=':Europe/London' date '+%Z %H:%M:%S')
产生:PDT 04:05:59 BST 12:05:59
但是,当我在 tmux 中执行此命令时,环境变量 TZ
似乎被破坏了.
However, it seems like the environment variable TZ
is clobbered when I execute this command within tmux.
set -g status-right "#(echo $(TZ=':US/Pacific' date '+%Z %H:%M:%S' && TZ=':Europe/London' date '+%Z %H:%M:%S'))"
在我的 tmux 状态栏中显示:PDT 04:09:01 PDT 04:09:01
.
Displays: PDT 04:09:01 PDT 04:09:01
in my tmux status bar.
我可以通过编写一个每次执行一个本地化日期命令的小型 shell 脚本来解决这个问题,但我不想依赖额外的文件.我试过使用 eval
但没有运气.任何帮助将不胜感激.
I can solve this by writing a small shell script that executes one localized date command at a time but I don't want to depend on an extra file. I've tried using eval
but no luck. Any help would be appreciated.
更新:
以下也不起作用.
set -g status-right "#(echo $(TZ=':US/Pacific' date '+%Z %H:%M:%S')) #(echo $(TZ=':Europe/London' date '+%Z %H:%M:%S'))"
推荐答案
解决方案是用另一个 % 转义 %,因为 tmux 通过 strftime 传递时间
The solution is to escape the % with another % as as tmux passes the times through strftime
这篇关于在 tmux 状态中设置环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!