48 lines
713 B
Plaintext
48 lines
713 B
Plaintext
|
#!/usr/bin/env perl
|
||
|
|
||
|
use strict;
|
||
|
use warnings;
|
||
|
|
||
|
my $pagesize = $ENV{'LINES'} || 22;
|
||
|
|
||
|
open(my $tty, '<', '/dev/tty')
|
||
|
or die "$0: Cannot open /dev/tty for reading: $!";
|
||
|
|
||
|
sub evalcmd {
|
||
|
{
|
||
|
chomp($_ = <$tty>);
|
||
|
if (/^q$/) {
|
||
|
exit(0);
|
||
|
} elsif (/^!(.*)/) {
|
||
|
system($1);
|
||
|
redo;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
sub printfile {
|
||
|
my ($fh) = @_;
|
||
|
my $lines = 0;
|
||
|
while (<$fh>) {
|
||
|
print;
|
||
|
&evalcmd unless ++$lines % $pagesize;
|
||
|
}
|
||
|
&evalcmd;
|
||
|
}
|
||
|
|
||
|
unshift(@ARGV, '-') unless @ARGV;
|
||
|
|
||
|
for (@ARGV) {
|
||
|
if (/^-$/) {
|
||
|
&printfile(\*STDIN);
|
||
|
} elsif (/^-(\d+)$/) {
|
||
|
$pagesize = $1;
|
||
|
} else {
|
||
|
open(my $fh, '<', $_) or die "$0: Cannot open $_ for reading: $!";
|
||
|
&printfile($fh);
|
||
|
close($fh);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
close($tty);
|