For my “hybrid” approach (terminal w/ tabs + tmux), this is the best solution I’ve found for the on-new-tab shell script:

#!/usr/bin/env sh
exec tmux $(tmux ls | grep -vq attached && echo "attach" || echo "new")

Reattaches orphan (which are rare!) tmux session or creates new; tabs close automatically on killed session/window.

Other solutions had various problems (orphans; multiple views into one session; etc.). This works.

Sign in to participate in the conversation

For people who care about, support, or build Free, Libre, and Open Source Software (FLOSS).