Skip to content

Tmux

The mastery of this terminal multiplexer will be invaluable. Live in it, learn it, love it.

I've recently moved my git command prompt into tmux to force myself to use it all the time because I rely on my git status as part of my terminals info feed back loop.

Problem is I'm having a spot of trouble getting tmux to branch from a main session like I want. If a user spawns a window when they themselves are not in a tmux session, the window is created and the user is connected to the session as expected. Problem is, every other tmux tab also focusses on that window that the user connected to.

I have a gist here which describes the issue.

#  if [[ $- =~ i ]] && [[ -z "$TMUX" ]] && [[ -n "$SSH_TTY" ]]; then
#   tmux attach-session -t ssh_tmux || tmux new-session -s ssh_tmux
# fi

if ! [ "$(tmux ls | cut -d: -f1)" = "trunk" ]; then
  tmux new-session -d -s trunk -n branch0
  tmux attach-session -t trunk:branch0
elif [[ -z "${TMUX}" ]]; then
  branch_id="$(tmux ls | cut -d ' ' -f2)"
  tmux new-window -d -n branch$branch_id -t trunk:
  tmux attach-session -t trunk:$branch_id
else
  branch_id="$(tmux ls | cut -d ' ' -f2)"
  tmux new-window -n branch$branch_id -t trunk:
fi

Thoughts?

I'm guessing this is where nested sessions may come in use. If planning to do this maybe a trap the nested session and windows I created under "trunk" to make sure I can clean up dangling dependency of this "fork" of session/windows.