2

So here's what I want:

  • On every tty login, fbterm starts. It gives me a better resolution than the linux console, has working UTF-8 support (I'm sure it's entirely my fault that the linux console doesn't have these two, but I can't get it to work), and gives me access to more windows (10 per fbterm).
  • In each fbterm window, tmux is running. The sessions between fbterm instances are completely independent, but in each fbterm window, the tmuxes share the same set of windows (but show different windows).

After some struggling, I have managed to achieve this - I intend to answer this question myself. Have you done something similar, or how would you solve this?

3 Answers 3

3

This here is what I have now, I tested it and it's working:

#!/bin/sh
if [[ -n "$TMUX" ]]; then
    echo "CRITICAL - ALREADY INSIDE TMUX!"
    echo "Dropping you into /bin/sh..."
    /bin/sh -i
    echo "Exiting with /bin/sh exit code..."
    exit $?
fi
SESSION="$(whoami)-$(basename $(tty))";
# Start tmux server if it isn't already running
echo "Starting tmux server..."
/usr/bin/tmux start-server
echo "tmux server started."
# Create the session if it doesn't exist
echo "Checking for tty session..."
if /usr/bin/tmux has-session -t "$SESSION" 2> /dev/null; then
    echo "tty session already present, will spawn new window later."
else
    echo "Creating tty session..."
    /usr/bin/tmux new-session -d -s "$SESSION" -n "$SESSION-dummywindow" /bin/bash
    echo "tty session created."
fi
# Create a new session that shares the windows of the existing (or new) session
echo "Starting fbterm and tmux..."
( sleep 1; /usr/bin/tmux kill-window -t "$SESSION-dummywindow" ) &
/usr/bin/fbterm -- /usr/bin/tmux new-session -t "$SESSION" \; new-window /bin/bash;

Put this into some file, make it executable, then run it from your .profile (or .bash_profile). The original intention was to directly use this script as your login shell, but that is currently unstable (works for my account, doesn't work for a newly-created dummy test account).

1
  • If this is the correct solution, please mark it as such.
    – Daniel B
    May 15, 2014 at 6:57
1

I use the following in my .bashrc, which I believe achieves nearly the same functionality:

if [ -z "$SSH_CONNECTION" ]; then
  # if in virtual terminal, start fbterm
  if [[ "$(tty)" =~ /dev/tty ]] && type fbterm > /dev/null 2>&1; then
    fbterm
  # otherwise, start/attach to tmux
  elif [ -z "$TMUX" ] && type tmux >/dev/null 2>&1; then
    tmux new -As "$(basename $(tty))"
  fi
fi

This will open fbterm (if possible) and then tmux in any new interactive shell. It will attach to a tmux session with the specified name if it exists, or create one if not.

0

Not sure it's the answer you're looking for but I've been struggling myself to get fbterm and tmux to autostart without getting in each other's way. This in .profile did the trick for me:

if [[ ! $TERM =~ screen ]]; then
   SHELL=tmux fbterm
fi

You must log in to answer this question.

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