#!/usr/bin/perl -w use strict; # Load all replays if( $#ARGV < 0 ) { die "$0 \n"; } my @replay = (); foreach my $file (@ARGV) { open my $handle, "<$file" or die $!; while( my $line = <$handle> ) { chomp $line; next unless $line =~ /^ruby \S+ \d+ [hjkl]+/; push @replay, $line; } close $handle; } # Infinite loop for(;;) { # Shuffle replays for(my $i = scalar @replay; $i--;) { my $j = int(rand($i + 1)); next if $i == $j; @replay[$i, $j] = @replay[$j, $i]; } # Run each replay foreach my $cmd (@replay) { if( system($cmd) != 0 ) { # If child process exited with nonzero status, it's probably # because user interrupted it with Ctrl+C. We want to exit # as gracefully as possible here. print "\e[0m\e[?25h\n\n\n\n\n"; exit 0; } } }