Skip to content

Instantly share code, notes, and snippets.

@rcrowley
Created May 23, 2013 20:53
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 rcrowley/5639344 to your computer and use it in GitHub Desktop.
Save rcrowley/5639344 to your computer and use it in GitHub Desktop.
VirtualBox-aware ssh(1)
#!/bin/sh
set -e
#/ Usage: ssh [...] [<username>@]<hostname>|<vmname> [...]
: ${BASE:="$HOME/VirtualBox VMs"}
usage() {
grep "^#/" "$0" | cut -c"4-" >&2
exit "$1"
}
while [ "$#" -gt 0 ]
do
case "$1" in
-1|-2|-4|-6|-A|-a|-C|-f|-g|-K|-k|-M|-N|-n|-q|-s|-T|-t|-V|-v|-X|-x|-Y|-y)
ARGS="$ARGS \"$1\"" shift;;
-b|-c|-D|-e|-F|-I|-i|-L|-l|-m|-O|-o|-p|-R|-S|-W|-w)
ARGS="$ARGS \"$1\" \"$2\"" shift 2;;
-b*|-c*|-D*|-e*|-F*|-I*|-i*|-L*|-l*|-m*|-O*|-o*|-p*|-R*|-S*|-W*|-w*)
ARGS="$ARGS \"$1\"" shift;;
*@*) break;;
*)
if [ -d "$BASE/$1" ]
then ARGS="-A -o StrictHostKeyChecking=\"no\" -o UserKnownHostsFile=\"/dev/null\" -p\"2222\" $ARGS \"localhost\""
else ARGS="$ARGS \"$1\""
fi
shift
break;;
esac
done
for ARG in "$@"
do ARGS="$ARGS \"$ARG\""
done
eval exec /usr/bin/ssh $ARGS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment