Skip to content

Instantly share code, notes, and snippets.

@Spaceghost
Created October 3, 2020 04:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Spaceghost/357ad4380e2be7e382d411a619edebe5 to your computer and use it in GitHub Desktop.
Save Spaceghost/357ad4380e2be7e382d411a619edebe5 to your computer and use it in GitHub Desktop.
autossh combined with tmux for a mosh like behaior
function smux {
AUTOSSH_POLL=10
AUTOSSH_PORT=$(awk 'BEGIN { srand(); do r = rand()*32000; while ( r < 20000 ); printf("%d\n",r) }' < /dev/null)
#AUTOSSH_GATETIME=30
#AUTOSSH_LOGFILE=autossh.$HOST.log
#AUTOSSH_DEBUG=yes
#AUTOSSH_PATH=/usr/local/bin/ssh
export AUTOSSH_POLL AUTOSSH_LOGFILE AUTOSSH_DEBUG AUTOSSH_PATH AUTOSSH_GATETIME AUTOSSH_PORT
case "$2" in
"") autossh $@ -t "if tmux -qu has; then tmux -qu attach; else EDITOR=vim tmux -qu new; fi";;
*) autossh $@ -t "if tmux -qu has -t $2; then tmux -qu attach -t $2; else EDITOR=vim tmux -qu new -s $2; fi";;
esac
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment