Skip to content

Instantly share code, notes, and snippets.

@otsuarez
Last active January 4, 2020 20:28
Show Gist options
  • Save otsuarez/21e9054f0d4632a9a9b5f43d8dddd0ed to your computer and use it in GitHub Desktop.
Save otsuarez/21e9054f0d4632a9a9b5f43d8dddd0ed to your computer and use it in GitHub Desktop.
tips for using mosh and tmux

Add to ~/.bashrc on client:

tmosh() {
  mosh --no-init $1 -- tmux new-session -ADs main
}  

Add to ~/.bashrc on server:

exit() {
  if [[ -z $TMUX ]]; then
    builtin exit
    return
  fi

  panes=$(tmux list-panes | wc -l)
  wins=$(tmux list-windows | wc -l) 
  count=$(($panes + $wins - 1))
  if [ $count -eq 1 ]; then
    tmux detach
  else
    builtin exit
  fi
}

References:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment