Skip to content

Instantly share code, notes, and snippets.

@marc-hanheide
Created October 6, 2014 16:00
Show Gist options
  • Save marc-hanheide/c805787b36702b6779c1 to your computer and use it in GitHub Desktop.
Save marc-hanheide/c805787b36702b6779c1 to your computer and use it in GitHub Desktop.
automatically start tmux in interactive ssh sessions (to be used in .bashrc)
case $- in
*i*) # interactive shell
if [ -z "$TMUX" ]; then
if [ "$SSH_CLIENT" ]; then
TMUX_SESSION=`echo ${SSH_CLIENT} | cut -f1 -d" "`
echo "checking for tmux session with ID $TMUX_SESSION"
if tmux has-session -t "$TMUX_SESSION" > /dev/null; then
exec tmux at -t "$TMUX_SESSION"
else
exec tmux new-session -s "$TMUX_SESSION"
fi
fi
fi
;;
*) # non-interactive shell
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment