Automatically launch a tmux session in a ZSH shell

Posted on April 01, 2015 in programmation, shell, zsh, tmux

At the end of your /root/.zshrc file :

if [[ -z "$TMUX" ]]
then
    ID="`tmux ls | grep -vm1 attached | cut -d: -f1`"
    if [[ -z "$ID" ]]
    then
        tmux new-session
    else
        tmux attach-session -t "$ID"
    fi
fi