Skip to content

Instantly share code, notes, and snippets.

@svanellewee
Created January 25, 2022 09:16
Show Gist options
  • Save svanellewee/2d5de20b0cd16f0433af95edbf45b01e to your computer and use it in GitHub Desktop.
Save svanellewee/2d5de20b0cd16f0433af95edbf45b01e to your computer and use it in GitHub Desktop.
Connect to the same tmux
# pop this in your bashrc
if [[ -z "$TMUX" ]] # hey bash, are you inside a tmux already? Then ignore!
then
# if bash is not currently in a tmux session, look for the first..
first_session=$(tmux ls 2>/dev/null|grep -Po '\K[0-9]+?(?=\: )')
if [[ ! -z "${first_session}" ]]
then
# oh you found a session! Attach to that badboy
tmux attach-session -t "${first_session}"
else
# Not running inside tmux, and no current session. MAKE ONE!
tmux
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment