Created
May 10, 2012 02:48
-
-
Save lexande/2650676 to your computer and use it in GitHub Desktop.
Wrapper script to use mosh when possible and fall back to ssh otherwise
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 || system("$mosh --ssh='$ssh' $host") == 1280) { | |
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