From 8b91bd5f929bf166ee3a79dec43fba0e68b1dc8e Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 21 Sep 2021 07:41:55 +0000 Subject: lei: various completion improvements "lei export-kw" no longer completes for anonymous sources. More commands use "lei refresh-mail-sync" as a basis for their completion work, as well. ";AUTH=ANONYMOUS@" is stripped from completions since it was preventing bash completion from working on AUTH=ANONYMOUS IMAP URLs. I'm not sure if there's a better way, but all of our code works fine without specifying AUTH=ANONYMOUS as a command-line arg. Finally, we fallback to using more candidates if none can be found, allowing multiple URLs to be completed. --- lib/PublicInbox/LeiMailSync.pm | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'lib/PublicInbox/LeiMailSync.pm') diff --git a/lib/PublicInbox/LeiMailSync.pm b/lib/PublicInbox/LeiMailSync.pm index 522a5ebc..91cd1c93 100644 --- a/lib/PublicInbox/LeiMailSync.pm +++ b/lib/PublicInbox/LeiMailSync.pm @@ -299,16 +299,19 @@ sub locations_for { # returns a list of folders used for completion sub folders { - my ($self, $pfx) = @_; - my $dbh = $self->{dbh} //= dbh_new($self); + my ($self, @pfx) = @_; my $sql = 'SELECT loc FROM folders'; - my @pfx; - if (defined $pfx) { + if (defined($pfx[0])) { $sql .= ' WHERE loc LIKE ? ESCAPE ?'; - @pfx = ($pfx, '\\'); + my $anywhere = !!$pfx[1]; + $pfx[1] = '\\'; $pfx[0] =~ s/([%_\\])/\\$1/g; # glob chars $pfx[0] .= '%'; + substr($pfx[0], 0, 0, '%') if $anywhere; + } else { + @pfx = (); # [0] may've been undef } + my $dbh = $self->{dbh} //= dbh_new($self); map { $_->[0] } @{$dbh->selectall_arrayref($sql, undef, @pfx)}; } -- cgit v1.2.3-24-ge0c7