1 # Copyright (C) all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
4 # "lei ls-external" command
5 package PublicInbox::LeiLsExternal;
9 # TODO: does this need JSON output?
11 my ($lei, $filter) = @_;
12 my $do_glob = !$lei->{opt}->{globoff}; # glob by default
13 my ($OFS, $ORS) = $lei->{opt}->{z} ? ("\0", "\0\0") : (" ", "\n");
15 my $re = $do_glob ? $lei->glob2re($filter) : undef;
16 $re //= index($filter, '/') < 0 ?
17 qr!/\Q$filter\E/?\z! : # exact basename match
18 qr/\Q$filter\E/; # grep -F semantics
19 my @ext = $lei->externals_each(my $boost = {});
20 @ext = $lei->{opt}->{'invert-match'} ? grep(!/$re/, @ext)
22 if ($lei->{opt}->{'local'} && !$lei->{opt}->{remote}) {
23 @ext = grep(!m!\A[a-z\+]+://!, @ext);
24 } elsif ($lei->{opt}->{remote} && !$lei->{opt}->{'local'}) {
25 @ext = grep(m!\A[a-z\+]+://!, @ext);
28 $lei->out($loc, $OFS, 'boost=', $boost->{$loc}, $ORS);