用 PERL 重写了 screen-wrapper
RT, 发现多个 session 时可以自己选择
#!/usr/bin/perl -w
#
# A wrapper for screen.
#
use strict ;
if (system("which screen > /dev/null") == 0) {
# screen is found
my $screen_command = `which screen` ;
chomp $screen_command ;
if ($#ARGV != -1) {
exec "$screen_command" , @ARGV ;
} else {
my @sock_list = `$screen_command -ls` ;
@sock_list = grep { s/^\s*// ; m/tached/ } @sock_list ;
if ($#sock_list == -1) {
exec "$screen_command"
} elsif ($#sock_list == 0) {
exec "$screen_command -x"
} else {
print "There are ",$#sock_list+1," screens. Please choose one to attache.\n\n";
for(my $i=0; $i <= $#sock_list; $i++) {
print " ",$i+1,"\t",$sock_list[$i];
}
print "\nPress ENTER to choose the first one for default.\n" ;
print "Your choice: ";
while (my $choice = <STDIN>) {
chomp $choice;
if ($choice eq '') {$choice = 1};
if (($choice =~ m/\d+/) && ($choice >=1 ) && ($choice <= $#sock_list+1)) {
$sock_list[$choice-1] =~ m/^(\S+).*$/ ;
exec $screen_command." -x $1";
} else {
print "Please choose from [1-",$#sock_list+1,"] : ";
}
}
}
}
}
else {
print STDERR "Error: screen not found. Have you installed screen?\n" ;
exit -1;
}