Skip to content

Instantly share code, notes, and snippets.

@moeffju
Forked from mariow/moshalias.pl
Last active December 14, 2015 23:59
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 moeffju/5170039 to your computer and use it in GitHub Desktop.
Save moeffju/5170039 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
my $ssh="/usr/bin/ssh";
my $mosh="/usr/bin/mosh";
my $host;
my $unsupported=0;
for (my $i=0; $i <= $#ARGV; $i++) {
if ($ARGV[$i] =~ /^-/) {
$ssh .= " \"$ARGV[$i]\"";
if ( grep { /$ARGV[$i]/ } ("-A","-C","-D","-e","-f","-g","-L","-M","-N","-n","-R","-V","-W","-w","-X","-Y") ) {
print "mosh does not support ssh's \"$ARGV[$i]\" option.\n";
$unsupported=1;
}
if ( grep { /$ARGV[$i]/ } ("-b","-c","-D","-e","-F","-I","-i","-L","-l","-m","-O","-o","-p","-R","-S","-W","-w") ) {
$ssh .= " \"$ARGV[$i+1]\"";
$i++;
}
} else {
$host=$ARGV[$i];
}
}
if (!$unsupported) {
# try running mosh
my $retval = system("$mosh --ssh='$ssh' $host");
$retval = $retval >> 8;
if ($retval == 127) { $unsupported = 1; }
}
if ($unsupported) {
print "Falling back to ssh...\n";
exec("$ssh $host");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment