与平铺窗口管理器一起使用时,终端多路复用器有什么好处吗?

Pub*_*bby 14 gnu-screen terminal-multiplexer tmux tiling-wm xmonad

终端多路复用器(screen、tmux)和键盘驱动的平铺窗口管理器(ratpoison、dwm、xmonad)都提供类似的功能。同时使用两者有什么好处吗?可能出现的问题怎么办?

jan*_*nos 19

终端多路复用器的额外好处是,您的多路复用器会话仍然有效,即使 X(您的桌面会话)崩溃,或者您从 X 注销,您也可以重新连接到它们。


Emi*_*mil 11

我使用 dwm 和 tmux。在学习使用 tmux 之前,我会为不同的事物打开多个终端,并将它们放在不同的标签中。现在,我可以在一个 tmux 会话中,在单个标签下运行所有​​内容,并且可以在需要重新启动 X 时分离和重新附加而不会丢失状态。


Ale*_*ies 6

使用两者:平铺窗口管理器和终端多路复用器。

结合双方的能力和优势,获得更好的协同效应。在我的 i3 设置中,我经常同时显示多个终端,但所有终端都连接到同一个 tmux 会话,因此我可以在任何终端中显示所有 tmux 窗口

实际上,我使用平铺功能i3来替换/增强终端多路复用器的窗口分割/移动功能,以(恕我直言)获得两全其美的效果。

这里使用以下脚本来管理会话/检测连接并在终端启动时进行清理:

#!/bin/bash
# This script attaches the terminal to a common session, where all
# terminals can show any window of the main tmux session independently
# This script also cleans up "old" sessions
# Todo: Cosmetic fix-ups. Make less verbose.

DEBUG="y"
showRun(){ echo Will run: $@;test -z $DEBUG||read -n1 -p"Press ENTER";$@; }

SNAME=${1:-XyZ}

if ! tmux has -t $SNAME; then
    echo -n "Session $SNAME not found, creating it: "
    showRun exec tmux new-session -s $SNAME;
else
    echo -n "Session $SNAME found: "
    MySESSION=$(tmux ls | grep -E "^$SNAME:.*\(attached\)$")
    echo $MySESSION;
    if [ -z "$MySESSION" ] ; then
        echo "Session $SNAME unattached, seizing it:"
        showRun exec tmux attach -t $SNAME \; new-window
    else
        echo "Session $SNAME already attached, finding grouped Sessions:"
        REGEX="group ([^)]*)"
        [[ $MySESSION =~ $REGEX ]]
        GNAME=${BASH_REMATCH[1]}
        GSESSIONS=$(tmux ls | grep "group $GNAME)" | grep -v $SNAME:)
        echo "$GSESSIONS"
        if [ -z "$GSESSIONS" ]; then
            echo "No sessions in group with $SNAME found, creating new one:"
            showRun exec tmux new-session -t $SNAME \; new-window
        else
            FGSESSIONS=$(echo "$GSESSIONS" | grep -v attached )
            if [ -z "$FGSESSIONS" ]; then
                echo "No free sessions in group $GNAME found, creating new one:"
                showRun exec tmux new-session -t $SNAME \; new-window
            else
                echo -e "Free grouped Sessions:\n $FGSESSIONS";
                if echo "$FGSESSIONS" | tail -n +2 | grep . > /dev/null; then
                    echo "Several detached Sessions found, cleaning up:"
                    echo "$FGSESSIONS" | while read SID x ; do
                        if [ -z $KEEPSID ]; then
                            KEEPSID=${SID%:*};
                            echo "Keeping session $KEEPSID for takeover after cleanup"
                        else
                            echo "Cleaning up old detached session $SID"
                            tmux kill-session -t ${SID%:}
                        fi;
                    done
                    KEEPSID=$(tmux ls|grep "group $GNAME)" | grep -v attached);
                    KEEPSID=${KEEPSID%: *}
                    echo "Attaching to session $KEEPSID:"
                    showRun exec tmux attach -t $KEEPSID \; new-window
                else
                    echo "Free session ( ${FGSESSIONS%: *} ) found, seizing it:"
                    showRun exec tmux attach -t ${FGSESSIONS%: *} \; new-window
                fi ;
            fi ;
        fi ;
    fi ;
fi
Run Code Online (Sandbox Code Playgroud)


mat*_*est 5

在这种情况下,终端多路复用器的另一个有用的方面是在连接到远程服务器之后。我发现的一个典型用例是

  1. 在我的本地电脑上打开终端窗口。
  2. ssh 到远程服务器。
  3. tmux/screen 现在在远程服务器上提供多路复用,允许在远程服务器上轻松打开新的终端/shell。与在本地电脑上打开第二个终端并使用第二个 ssh 重新连接相比,这少了一步。