即使主终端 windows 已关闭,如何使 tmux 会话保持活动状态?

How to keep tmux session alive even the main terminal windows is closed?

我的目标是即使主终端 windows 关闭也能保持 tmux 会话有效。我想知道这可能吗?


当我关闭主终端时 window tmux 会话结束但如果我在终端中关闭单个 windows 则它不会。

如果有两个或多个 windows 或选项卡,当我关闭其中一个时,会话仍然继续并且没有任何反应。但是当我关闭会话中最后剩下的 window 时,它将终止正在进行的 tmux 会话。

可能的情况,当终端打开时使用 ssh 远程连接 tmux 会话;如果我用左上角的圆圈关闭 iTerm2,我正在进行的 tmux 会话将终止。

屏幕视图示例:

❯ which goo
goo: aliased to ssh -xt4C user@IP


有人告诉我 iTerm2 issues:

What you're closing are window panes, not windows. If you close the last window pane it detaches because tmux automatically detaches when there are no more window panes left. This is consistent with tmux's behavior outside tmux integration. I don't believe tmux has a way to disable this behavior, although it would not be unreasonable to ask for such a change (this would need to be done by tmux, and I could later add support for it)


我的tmux配置:

您是否尝试过使用 nohup 命令启动 tmux?每当我想从 Linux 中的 shell 启动程序时,我通常会使用此命令,并且我不希望在关闭从中启动它的终端仿真器时终止该程序。例如。要启动名为 zathura 的 PDF reader,我会使用 nohup zathura file.pdf & 之类的东西,然后我也可以在不关闭 zathura 的情况下关闭终端仿真器。希望这也适用于 macOS。

Latest quote from George Nachman in your Gitlab issue:

Depends if the close button is bound to hide the window or kill the window. If it's set to kill then you would not be able to get the window back by reattaching

因此,您似乎只是希望绑定按钮以隐藏 window。正如我在评论中所说,默认情况下,iTerm2 应该询问您要做什么:

如果您曾经在此处选中“记住我的选择”并单击终止,这就是 iTerm2 现在为您所做的。

我在文档中找不到任何关于在哪里重置它的条目,但是 this google groups discussion George 说:

There's a prompt which shows by default but can be permanently suppressed. If you'd like it back, turn off Prefs > Advanced > Suppress kill/hide dialog when closing a tmux tab. There's another similarly named advanced pref for tmux windows.

讨论是从 2018 年开始的,但是 this option can still be found in the code,所以我认为它仍然存在。

因此,您可能希望在关闭 tmux window.

时禁用首选项 > 高级 > 抑制 kill/hide 对话框