Skip to content

Instantly share code, notes, and snippets.

@mariow
Forked from lexande/moshalias.pl
Last active August 31, 2023 11:13
Show Gist options
  • Save mariow/5169873 to your computer and use it in GitHub Desktop.
Save mariow/5169873 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
my $ssh=`which ssh`;
my $mosh=`which mosh`;
chomp($ssh);
chomp($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];
}
}
# mosh doesn't for dntx at the moment
if ($host =~ /us-east1.dntx.com/) {
print "Unsupported host\n";
$unsupported = 1;
}
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");
}
@mariow
Copy link
Author

mariow commented Mar 15, 2013

Modified to support multiple failure return codes (mosh seems to quit with 32512 on OSX)

@moeffju
Copy link

moeffju commented Mar 15, 2013

Siehe mein Fork https://gist.github.com/moeffju/5170039 - system() gibt den Exit-Code in den oberen acht Bits zurück, du musst also 8 Bit nach rechts shiften.

@mariow
Copy link
Author

mariow commented Mar 15, 2013

Stimmt, viel eleganter - hab ich direkt mal so übernommen :)

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