From 1bd9e76d6e93128e50e175b67aba82ad7c9f6036 Mon Sep 17 00:00:00 2001 From: "David Todd (c0de)" Date: Wed, 16 May 2018 19:23:26 -0500 Subject: [PATCH] New tmux startup system The first running shell on the system should launch tmux automatically Future shells being opened on the same system will not automatically launch tmux It does not matter if you later detach from that initial session (you can rejoin with `ta`) --- shell/env | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/shell/env b/shell/env index 8afbf81..2420ced 100644 --- a/shell/env +++ b/shell/env @@ -21,8 +21,18 @@ export DISABLE_DOTFILES_UPDATE_PROMPT="FALSE" # Update every 2 weeks (OMZ default) export UPDATE_DOTFILES_DAYS=13 -# Disabled for now because I've found this fairly annoying on macos with iTerm2 -# Automatically attach tmux session "C0DE" upon entering a shell -# if [[ -z "$TMUX" ]]; then -# tmux attach -t C0DE || tmux new -s C0DE -# fi +# Whether or not to automatically connect to a TMUX session when opening the shell +export DISABLE_TMUXAC="TRUE" + +# If there is not an active tmux session, we probably want one +# Otherwise, the shell will not open the session again (eg. opening tabs, new terminals) +if $(tmux list-sessions >> /dev/null 2>&1); then + export TMUXATT="TRUE" +else + export TMUXATT="FALSE" +fi + +# Automatically attach tmux session "C0DE" +if [[ -z "$TMUX" && "$TMUXATT" != "TRUE" && "$DISABLE_TMUXAC" != "FALSE" ]]; then + tmux attach -t C0DE || tmux new -s C0DE +fi