Commit c9c96d64 authored by Dom Sekotill's avatar Dom Sekotill
Browse files

Handle SSH differences across platforms with a preloader

parent 52b3a95e
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -19,6 +19,9 @@ alias grep='~/.shell/bin/grep-auto-exclude grep -n'
alias fgrep='~/.shell/bin/grep-auto-exclude fgrep -n'
alias egrep='~/.shell/bin/grep-auto-exclude egrep -n'

# special SSH
alias ssh='~/.ssh/ssh'


## Common miss-spellings
## =====================

.ssh/ssh

0 → 100755
+54 −0
Original line number Diff line number Diff line
#!/bin/sh
set -eu

ssh_version() {
	eval `ssh -V 2>&1 | sed -n \
		's/OpenSSH_\([0-9]\+\)\.\([0-9]\+\).*/SSH_MAJOR="\1" SSH_MINOR="\2"/p'`
}

platform() {
	case `uname` in
		Linux*) PLATFORM=linux ;;
		CYGWIN*) PLATFORM=windows ;;
		Darwin*) PLATFORM=darwin ;;
		*) echo >&2 "Unrecognised platform: `uname`"; exit 2 ;;
	esac
}

rule_unix_sockets() {
	# Windows has no unix sockets so disable shared connections
	# (Control* settings)
	if [ $PLATFORM = windows ]; then
		echo '/^\s*Control.*/d;'
	fi
}

rule_canonisation() {
	# OpenSSH < 6.6 does not have name canonisation
	# (Canonical* settings)
	if [ $SSH_MAJOR -gt 6 ]; then return; fi
	if [ $SSH_MAJOR -lt 6 ] || [ $SSH_MINOR -lt 6 ]; then
		echo '/Canonical/d;'
	fi
}

make_config() {
	platform && ssh_version

	CONFIG=`mktemp -p ~/.ssh/ .config.XXXXXX`
	trap 'rm "$CONFIG"' EXIT

	cat ~/.ssh/config ~/.ssh/config.local 2>/dev/null |
		sed >"$CONFIG" "
			`rule_unix_sockets`
			`rule_canonisation`
		"
}

case " $*" in
	*' -F'*) command ssh "$@" ;;
	*)
		make_config
		command ssh -F $CONFIG "$@"
		;;
esac