22

Both terminal multiplexers (screen, tmux) and keyboard-driven tiling window managers (ratpoison, dwm, xmonad) provide similar functionality. Is there any benefit in using both at the same time? What about problems that may arise?

3
  • 1
    They do? The only feature I can think of that overlaps is the ability to split a window into many Commented May 16, 2012 at 5:33
  • @MichaelMrozek I have 0 experience with either of them so I'm just going of some stuff I've read. It would be great if you could point out some differences.
    – Pubby
    Commented May 16, 2012 at 5:52
  • 3
    Be aware that for a window manager, every window is just a window – and that's about it. Therefore lots of terminal-related things apart from window splitting are unavailable to the WM.
    – sr_
    Commented May 16, 2012 at 8:21

5 Answers 5

23

The added benefit of terminal multiplexers is that your multiplexer sessions will still be alive and you can reconnect to them even if X (your desktop session) crashes, or you logged out of X.

13

I use dwm and tmux. Before learning to use tmux, I would have multiple terminals open for different things, and have them in different tags. Now I can run everything inside of one tmux session, under a single tag, and can detach and reattach without losing state if I need to restart X.

6

Use both: A tiling window manager, and a terminal multiplexer.

Combine both their capabilities and advantages to obtain an even better synergy. On my i3 setup I regularly display several terminals at the same time, but all of them connected to the same tmux session, so I can display all tmux windows in any of the terminals.

In effect, I use the tiling capabilities of i3 to replace/augment the window splitting/moving functionality of the terminal multiplexer to (imho) get the best of both worlds.

The below script is used here to manage session /detection connection and clean-up on terminal startup:

#!/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
5

Another useful aspect of a terminal multiplexer in this scenario is after connecting to remote servers. A typical use case I find is

  1. Open a terminal window on my local pc.
  2. ssh into a remote server.
  3. tmux/screen now provides multiplexing on the remote server, allowing easy opening of new terminals/shells on the remote server. Compared to opening a second terminal on local pc and re-connecting with a second ssh, this is one fewer step.
1

No. In those rare cases where screen inside of screen or tmux inside of tmux is useful, both programs provide a simple means of passing control to the nested instance.

Screen offers serial console capabilities, but I just use a dedicated app (miniterm.py distributed with python) when I need that. Otherwise I can't think of anything offhand that either can do and the other can't, but one might do it simpler than the other.

I would learn one or the other, and if you're curious or dissatisfied with what you picked, try the other. I prefer tmux, personally.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .