Permalink
Browse files

Add -1 and -n options to menupick program

-1 tells menupick that if there is only a single item, to select it
and continue without presenting a menu.

-n N changes the upper limit on menu size to N from the default of 30.
-n 0 disables the limit.
  • Loading branch information...
1 parent 1e6f206 commit 05391564831dcf86eab92188b9cca8322d754ec1 Mark Dominus committed Oct 30, 2012
Showing with 10 additions and 1 deletion.
  1. +10 −1 menupick
View
@@ -1,12 +1,21 @@
#!/usr/bin/perl
+use Getopt::Std;
+my $opt = { 1 => 0, n => 30 };
+getopts('1n:', $opt) or usage();
+
chomp(my @item = <>);
open my($ttyin), "<", "/dev/tty"
or do { warn "No tty: $!\n"; exit 1 };
open my($ttyout), ">", "/dev/tty"
or do { warn "No tty: $!\n"; exit 1 };
-if (@item > 30) {
+if ($opt->{1} && @item == 1) {
+ print @item, "\n";
+ exit;
+}
+
+if ($opt->{n} > 0 && @item > $opt->{n}) {
warn sprintf "%d items in menu is too many\n", 0+@item;
exit 2;
}

0 comments on commit 0539156

Please sign in to comment.