From d4f09d6bffabce43cb13620504ea2be57d800d05 Mon Sep 17 00:00:00 2001 From: Corrado Primier Date: Sun, 31 Jan 2021 14:19:01 +0000 Subject: [PATCH] ssh_to: rename to mosh_to, add a 'real' ssh_to --- bin/mosh_to | 27 +++++++++++++++++++++++++++ bin/ssh_to | 8 ++++---- 2 files changed, 31 insertions(+), 4 deletions(-) create mode 100755 bin/mosh_to diff --git a/bin/mosh_to b/bin/mosh_to new file mode 100755 index 0000000..8d234f3 --- /dev/null +++ b/bin/mosh_to @@ -0,0 +1,27 @@ +#!/bin/bash +# Connect to a remote tmux session with mosh, avoiding involuntary nesting +# +# This script is not intended to be run by itself. To use it, set up a link +# to it in your path for each server you want to connect to. The link name +# will be used as an ssh destination, so it has to be either a hostname or +# an alias defined in your ~/.ssh/config. + +if [[ ! -h $0 ]] ; then + echo "Error: this script should never be called directly" + exit 1 +fi + +if [[ $# != 0 ]] ; then + echo "Error: this scripts takes no pris^H^H^H^Hparameters" + exit 1 +fi + +MOSH=`command -v mosh` +HOST=${0##/*/} + +if [[ ! -z $TMUX ]] ; then + echo "Error: local tmux session detected, aborting to avoid nesting" + exit 1 +fi + +"${MOSH}" "${HOST}" -- sh -c "tmux a || tmux" diff --git a/bin/ssh_to b/bin/ssh_to index f8c80e9..820c250 100755 --- a/bin/ssh_to +++ b/bin/ssh_to @@ -1,10 +1,10 @@ #!/bin/bash -# Connect to a remote tmux session with mosh, avoiding involuntary nesting +# Connect to a remote tmux session with ssh, avoiding involuntary nesting # # This script is not intended to be run by itself. To use it, set up a link # to it in your path for each server you want to connect to. The link name # will be used as an ssh destination, so it has to be either a hostname or -# an alias definet in your ~/.ssh/config. +# an alias defined in your ~/.ssh/config. if [[ ! -h $0 ]] ; then echo "Error: this script should never be called directly" @@ -16,7 +16,7 @@ if [[ $# != 0 ]] ; then exit 1 fi -MOSH=`command -v mosh` +SSH=`command -v ssh` HOST=${0##/*/} if [[ ! -z $TMUX ]] ; then @@ -24,4 +24,4 @@ if [[ ! -z $TMUX ]] ; then exit 1 fi -"${MOSH}" "${HOST}" -- sh -c "tmux a || tmux" +"${SSH}" -t "${HOST}" -- sh -c "tmux a || tmux"