]> code.delx.au - monosys/blob - hacks/ssh-screen-wrapper
ssh-screen-wrapper: more flexible line matching
[monosys] / hacks / ssh-screen-wrapper
1 #!/bin/bash
2
3 set -eu
4
5 hostname="$(basename "$0")"
6 local_hostname="${hostname}.localnet"
7 public_hostname="p${hostname}"
8
9 if grep -Eq "^Host ${hostname}\b" ~/.ssh/config; then
10 true
11 elif ping -c1 -t1 "$local_hostname" &> /dev/null; then
12 hostname="$local_hostname"
13 else
14 hostname="$public_hostname"
15 fi
16
17 while true; do
18 clear
19 echo "Connecting to ${hostname}..."
20 ssh \
21 -o ServerAliveInterval=1 \
22 -o ServerAliveCountMax=5 \
23 -t \
24 "$@" \
25 "$hostname" \
26 "bash --login -c 'screen -dR'" \
27 && exit 0
28 echo "Disconnected, waiting..."
29 echo -ne "\\033]0;${hostname}: disconnected!\\007"
30 sleep 1
31 done
32