Adolfo Perez Alvarez
3e32f1b04e
Pick will take stdin and all command line arguments and display a ksh-like selection menu will all input lines/arguments.
36 lines
606 B
Perl
Executable File
36 lines
606 B
Perl
Executable File
#!/usr/bin/env perl
|
|
|
|
use strict;
|
|
use warnings;
|
|
|
|
use Scalar::Util qw{looks_like_number};
|
|
|
|
my @choices;
|
|
|
|
for (@ARGV) {
|
|
if (/^--$/) {
|
|
push(@choices, <STDIN>);
|
|
} elsif (/^@(.+)$/) {
|
|
open(my $fh, '<', $1);
|
|
push(@choices, <$fh>);
|
|
close($fh);
|
|
} else {
|
|
push(@choices, "$_\n");
|
|
}
|
|
}
|
|
|
|
open(my $tty, '<', '/dev/tty');
|
|
|
|
my $sel;
|
|
until (looks_like_number($sel) && $sel > 0 && $sel <= @choices) {
|
|
while (my ($i, $c) = each @choices) {
|
|
print $i+1 . ') ' . $choices[$i];
|
|
}
|
|
print $ENV{'PS3'} || '#? ';
|
|
exit(1) unless defined($sel = <$tty>);
|
|
}
|
|
|
|
close($tty);
|
|
|
|
print $choices[$sel - 1];
|