#!/bin/sh
# https://github.com/tmshn/dotfiles/blob/master/bin/autotmux
if ! type tmux > /dev/null 2>&1; then
echo 'tmux is not available.' >&2
exit 1
fi
if [ -n "${TMUX}" ]; then
echo 'already in tmux session.' >&2
exit
fi
if tmux has-session 2> /dev/null; then
tmux attach
exit
fi
readonly config="${XDG_CONFIG_HOME}/tmux/tmux.conf"
if [ ! -e "${config}" ]; then
echo 'config file not found!' >&2
exit 1
fi
tmux -f "${config}" new
Test this out and modify as needed.