Shell Tmux还原创建一个空会话

Shell Tmux还原创建一个空会话,shell,tmux,Shell,Tmux,我正在使用tmuxcontinuum和tmuxresurrect插件。如果我杀死tmux(例如重新启动我的机器),然后运行以下命令: $ tmux ls $ failed to connect to server: No such file or directory 然后,当我启动tmux时,它会自动恢复我保存的会话以及一个未命名的会话(通常是0) 我当前的工作流程如下所示: 启动tmux 从tmux中分离 附加到未命名的会话 终止未命名会话 附加到我保存的会话之一 我不想每次重新启动tm

我正在使用
tmuxcontinuum
tmuxresurrect
插件。如果我杀死tmux(例如重新启动我的机器),然后运行以下命令:

$ tmux ls
$ failed to connect to server: No such file or directory
然后,当我启动tmux时,它会自动恢复我保存的会话以及一个未命名的会话(通常是
0

我当前的工作流程如下所示:

  • 启动
    tmux
  • tmux中分离
  • 附加到未命名的会话
  • 终止未命名会话
  • 附加到我保存的会话之一
我不想每次重新启动tmux时都重复这一点。如何在不创建未命名会话的情况下恢复已保存的tmux会话?

运行以下命令(最好为其创建别名):

旗帜含义:

-s refers to session name.
-A In case session-name exists, command will act like attach-session instead of new-session.
有关官方文档,请参阅手册页:

$ man tmux

new-session [-AdDEP] [-c start-directory] [-F format] [-n window-name] [-s session-name] [-t
        target-session] [-x width] [-y height] [shell-command]
              (alias: new)
        Create a new session with name session-name.

        The new session is attached to the current terminal unless -d is given.  window-name and
        shell-command are the name of and shell command to execute in the initial window.  If -d
        is used, -x and -y specify the size of the initial window (80 by 24 if not given).

        If run from a terminal, any termios(4) special characters are saved and used for new win‐
        dows in the new session.

        The -A flag makes new-session behave like attach-session if session-name already exists;
        in this case, -D behaves like -d to attach-session.

        If -t is given, the new session is grouped with target-session.  This means they share
        the same set of windows - all windows from target-session are linked to the new session,
        any new windows are linked to both sessions and any windows closed removed from both ses‐
        sions.  The current and previous window and any session options remain independent and
        either session may be killed without affecting the other.  -n and shell-command are
        invalid if -t is used.

        The -P option prints information about the new session after it has been created.  By
        default, it uses the format ‘#{session_name}:’ but a different format may be specified
        with -F.

        If -E is used, the update-environment option will not be applied.

如果我正确理解您的问题,这是一个带有
tmux resurrect
的问题。给出的解决方案(目前是Github讨论中的最后一条评论)对我很有效

将以下内容添加到
.tmux.conf
中,然后执行
source~.tmux.conf
(如果这是conf文件的路径):

这是一个for
tmux resurrect
,它告诉它在恢复面板之前终止会话0


注意:由于会话的名称(
-t=0
)是硬编码的,因此它只适用于该会话,因此只有在第一次启动tmux服务器时进行还原时,如果在0之后从会话还原,则不会发生任何事情(这很好,可以避免意外终止会话).

您只需通过
tmuxa
启动tmux(即附加到“现有”会话)。这将触发tmux continuum,首先恢复所有会话,然后连接到其中一个会话


对我来说很好。我正在使用tmux resurrect和tmux continuum插件运行tmux 3.0a。

对我不起作用。它说它无法连接或其他什么。看起来这是一个月前修复的,但我还没有测试它。
-s refers to session name.
-A In case session-name exists, command will act like attach-session instead of new-session.
$ man tmux

new-session [-AdDEP] [-c start-directory] [-F format] [-n window-name] [-s session-name] [-t
        target-session] [-x width] [-y height] [shell-command]
              (alias: new)
        Create a new session with name session-name.

        The new session is attached to the current terminal unless -d is given.  window-name and
        shell-command are the name of and shell command to execute in the initial window.  If -d
        is used, -x and -y specify the size of the initial window (80 by 24 if not given).

        If run from a terminal, any termios(4) special characters are saved and used for new win‐
        dows in the new session.

        The -A flag makes new-session behave like attach-session if session-name already exists;
        in this case, -D behaves like -d to attach-session.

        If -t is given, the new session is grouped with target-session.  This means they share
        the same set of windows - all windows from target-session are linked to the new session,
        any new windows are linked to both sessions and any windows closed removed from both ses‐
        sions.  The current and previous window and any session options remain independent and
        either session may be killed without affecting the other.  -n and shell-command are
        invalid if -t is used.

        The -P option prints information about the new session after it has been created.  By
        default, it uses the format ‘#{session_name}:’ but a different format may be specified
        with -F.

        If -E is used, the update-environment option will not be applied.
set -g @resurrect-hook-pre-restore-pane-processes 'tmux switch-client -n && tmux kill-session -t=0'