Tmux还原会创建一个空会话

时间:2016-12-05 23:44:48

标签: shell tmux

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

$ tmux ls
$ failed to connect to server: No such file or directory

然后,当我启动tmux时,它会自动恢复已保存的会话加上一个未命名的会话(通常是0

$ tmux
$ tmux ls
  0: 1 windows (created...)
  saved_session_1: 1 windows (created...)
  saved_session_2: 1 windows (created...)
  ...

我目前的工作流程如下:

  • 开始tmux
  • tmux
  • 分离
  • 附加到未命名的会话
  • 杀死未命名的会话
  • 附加到我保存的其中一个会话

每次重启tmux时我都不想重复这个。如何在不创建未命名会话的情况下恢复已保存的tmux会话?

3 个答案:

答案 0 :(得分:1)

如果我正确理解您的问题,这是一个tmux-resurrect的{​​{3}}。 common issue提供的解决方案(当前是Github讨论中的最后一条评论)对我有用。

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

set -g @resurrect-hook-pre-restore-pane-processes 'tmux switch-client -n && tmux kill-session -t=0'

这是tmux-resurrect的{​​{3}},它告诉它在恢复面板之前杀死会话0。

注意:由于会话名(-t=0)是硬编码的,因此仅适用于该会话,因此,只有在首次启动tmux服务器时确实进行了还原,并且从0不会发生任何事情(最好避免意外终止会话)。

答案 1 :(得分:0)

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

-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.

有关官方文档,请参阅手册页:

mean, var = tf.nn.moments(input, axes=[0,1,2])

答案 2 :(得分:0)

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

对我来说很好。我正在使用带有tmux-resurrect和tmux-continuum插件的tmux 3.0a。