-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy paths
executable file
·61 lines (49 loc) · 1.05 KB
/
s
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/perl
use strict;
use warnings;
if ($ARGV[0] && $ARGV[0] eq '-h') {
print <<'EOS';
Usage: s [id|name]
id is session number, not pid. Run s without args to see session id.
Name is session name
EOS
exit;
}
my @sessions;
my $i = 1;
my @buffer = `screen -ls`;
if ($buffer[0] =~ m/No Sockets found/) {
die(" No existing SCREEN session to reattach to...\n");
}
print <<'EOS';
CURRENT SESSIONS
------------------------
EOS
for (@buffer) {
if (m/(\d+\..*?)\.?\s*\((Detached|Attached)\)/) {
push (@sessions, $1);
print " $i. $1\n";
++$i;
}
}
print " ------------------------\n";
my $input;
if (scalar @ARGV) {
chomp($input = $ARGV[0]);
} else {
print "\n Reattach to session: ";
chomp($input = <>);
}
my $session;
if ($input =~ m/^\d+$/ && $input > 0 && $input < $i) {
$session = $sessions[$input-1];
} else {
for (@sessions) {
$session = $1 if (m/(.*\.$input$)/);
}
}
if ($session) {
`screen -d -r $session`;
} else {
print " Could not reattach to '$input'\n";
}