Skip to content

Instantly share code, notes, and snippets.

@polds
Forked from lexande/moshalias.pl
Last active August 29, 2015 14:04
Show Gist options
  • Save polds/ec764ee9438e1b9d0246 to your computer and use it in GitHub Desktop.
Save polds/ec764ee9438e1b9d0246 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];
}
}
my $res=system("$mosh --ssh='$ssh' $host");
if ( $unsupported || $res == 1280 || $res == 32512) {
print "Falling back to ssh...\n";
exec("$ssh $host");
}
@polds
Copy link
Author

polds commented Jul 28, 2014

Added a $res == 32512 check.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment