| Subcribe via RSS

mysql_pager

#!/usr/bin/perl

use strict;
use warnings FATAL => ‘all’;
use English qw ( -no_match_vars );
use Term::ReadKey;

my $out;

while ( my $line = <STDIN>) {
$out .= $line;
}

# Log current result to a file (always useful)
open (PAGER_LOG, ‘>/tmp/mysql_pager.log’);
print PAGER_LOG “$out\n”;
close (PAGER_LOG);

# See if it is an EXPLAIN
eval {
local $SIG{’__WARN__’};
system(’/usr/local/bin/mk-visual-explain /tmp/mysql_pager.log 2> /dev/null’);
};

if ($?) {
# Use less if the output is taller than your terminal
my ( $cols, $lines ) = GetTerminalSize();
my @out_array = split("\n", $out);
if ( scalar ( @out_array ) > $lines ) {
system('less /tmp/mysql_pager.log');
} else {
print $out;
}
}