]> Sergey Matveev's repositories - public-inbox.git/commitdiff
lei: complete basenames for include|exclude|only
authorEric Wong <e@80x24.org>
Wed, 3 Feb 2021 08:11:39 +0000 (22:11 -1000)
committerEric Wong <e@80x24.org>
Thu, 4 Feb 2021 01:37:09 +0000 (01:37 +0000)
This will make it even easier for RSI-afflicted users to use,
since many externals may share a common prefix.

lib/PublicInbox/LeiQuery.pm

index 10b8d6fae68339ab81df2ed1e3c268f204ac102e..8015ecec6230a2fb222e6bb158cc77f2ef55eb42 100644 (file)
@@ -112,11 +112,22 @@ sub lei_q {
 sub _complete_q {
        my ($self, @argv) = @_;
        my $ext = qr/\A(?:-I|(?:--(?:include|exclude|only)))\z/;
-       # $argv[-1] =~ $ext and return $self->_complete_forget_external;
        my @cur;
        while (@argv) {
                if ($argv[-1] =~ $ext) {
                        my @c = $self->_complete_forget_external(@cur);
+                       # try basename match:
+                       if (scalar(@cur) == 1 && index($cur[0], '/') < 0) {
+                               my $all = $self->externals_each;
+                               my %bn;
+                               for my $loc (keys %$all) {
+                                       my $bn = (split(m!/!, $loc))[-1];
+                                       ++$bn{$bn};
+                               }
+                               push @c, grep {
+                                       $bn{$_} == 1 && /\A\Q$cur[0]/
+                               } keys %bn;
+                       }
                        return @c if @c;
                }
                unshift(@cur, pop @argv);