小编Spi*_*kes的帖子

如何检测是否附加了 tmux?

我有一个在 tmux 会话中运行的 Irssi,并且正在编写 Irssi 脚本(扩展),以便在有人 PM 或在我未连接到 tmux 会话时提及我时向我发送电子邮件。

关于这一点的一切都非常简单,少一件事:如何检测是否附加了 tmux 会话?

我已经做到了这一点,我在这里主要是想看看这是否是正确/最好的方法,或者我是否应该以不同的方式去做。任何建议表示赞赏!

# Get the current session_name value from tmux
$ tmux display -p '#{session_name}'
2

# Running list-clients while I'm attached yields the following,
# from both the same window as well as another window:
$ tmux list-clients -t 2
(null): 2 [180x42 (null)] 

# As well, running list-clients while detached yields no output:
$ tmux list-clients -t 2
$ 
Run Code Online (Sandbox Code Playgroud)

总而言之,我认为这是解决此问题的正确方法,但我当然愿意接受任何更好的方法或有关如何检查的建议。

tmux

7
推荐指数
2
解决办法
4652
查看次数

标签 统计

tmux ×1