scriptamanent/bin/ssh_to

28 lines
748 B
Bash
Executable File

#!/bin/bash
# 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 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
SSH=`command -v ssh`
HOST=${0##/*/}
if [[ ! -z $TMUX ]] ; then
echo "Error: local tmux session detected, aborting to avoid nesting"
exit 1
fi
"${SSH}" -t "${HOST}" -- sh -c "tmux a || tmux"