mirror of
https://github.com/git-learning-game/oh-my-git.git
synced 2025-05-01 20:42:01 +02:00
Start working on a better shell mechanism for Windows
It uses a Perl script to keep a bash session open, which attaches to a port the game keeps open. This avoids having to start a new Git bash for each command, improving the execution speed by a factor of 3-4.
This commit is contained in:
parent
2a82b617be
commit
53c249d059
8 changed files with 145 additions and 15 deletions
scripts
|
@ -1,24 +1,61 @@
|
|||
#!/usr/bin/env perl
|
||||
|
||||
use IPC::Open2;
|
||||
use IO::Socket;
|
||||
|
||||
my $pid = open2(my $out, my $in, 'bash');
|
||||
|
||||
$socket = IO::Socket::INET->new(PeerAddr => "127.0.0.1",
|
||||
PeerPort => 6666,
|
||||
Proto => "tcp",
|
||||
Type => SOCK_STREAM);
|
||||
|
||||
$s = "Hey äöü!";
|
||||
|
||||
my $send_length = pack("L", length($s));
|
||||
$socket->send($send_length);
|
||||
$socket->send($s);
|
||||
#$s = "Hey äöü!";
|
||||
#
|
||||
#my $send_length = pack("L", length($s));
|
||||
#$socket->send($send_length);
|
||||
#$socket->send($s);
|
||||
|
||||
while(true) {
|
||||
#STDOUT->flush();
|
||||
my $len;
|
||||
$socket->recv($len, 4);
|
||||
my $actual_len = unpack("L", $len);
|
||||
if ($actual_len == 0) {
|
||||
print("not connected");
|
||||
exit;
|
||||
}
|
||||
print("still connected");
|
||||
my $s2;
|
||||
$socket->recv($s2, ord($len));
|
||||
|
||||
print($s2);
|
||||
STDOUT->flush();
|
||||
|
||||
#$s = `bash -c '$s2' 2>&1`;
|
||||
|
||||
$s = "";
|
||||
$command = $s2 . "\necho MAGIC\n";
|
||||
print $in $command;
|
||||
|
||||
inner_while: while (true) {
|
||||
$line = <$out>;
|
||||
if ($line eq "MAGIC\n") {
|
||||
STDOUT->flush();
|
||||
last inner_while;
|
||||
}
|
||||
$s = $s . $line;
|
||||
}
|
||||
print "got complete output";
|
||||
print $s;
|
||||
|
||||
print length($s);
|
||||
STDOUT->flush();
|
||||
my $send_length = pack("L", length($s));
|
||||
$socket->send($send_length);
|
||||
$socket->send($s);
|
||||
|
||||
my $exit_code = pack("L", 0);
|
||||
$socket->send($exit_code);
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue