about summary refs log tree commit homepage
path: root/lib/PublicInbox/LeiMark.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2021-03-23 11:02:18 +0600
committerEric Wong <e@80x24.org>2021-03-24 01:33:26 +0000
commit767f310dcd887066c7263cfe6093f7529ffe631c (patch)
treeb08317c4eba61e129513a7dde9868ff9201ccde6 /lib/PublicInbox/LeiMark.pm
parent5be0cb101bab44167a78af7a2d167f254c95bdb3 (diff)
downloadpublic-inbox-767f310dcd887066c7263cfe6093f7529ffe631c.tar.gz
Only lightly tested, this seems to suffer from the same
problem as external completions for network URLs with
colons in them.  In any case, its usable enough for me.

The core LEI module now supports completions for lazy-loaded
commands, too, so we'll be able to do completions for other
commands more easily.
Diffstat (limited to 'lib/PublicInbox/LeiMark.pm')
-rw-r--r--lib/PublicInbox/LeiMark.pm43
1 files changed, 43 insertions, 0 deletions
diff --git a/lib/PublicInbox/LeiMark.pm b/lib/PublicInbox/LeiMark.pm
index aa52ad5a..7b50aa51 100644
--- a/lib/PublicInbox/LeiMark.pm
+++ b/lib/PublicInbox/LeiMark.pm
@@ -174,4 +174,47 @@ sub ipc_atfork_child {
         PublicInbox::OnDestroy->new($$, \&note_missing, $self);
 }
 
+# Workaround bash word-splitting s to ['kw', ':', 'keyword' ...]
+# Maybe there's a better way to go about this in
+# contrib/completion/lei-completion.bash
+sub _complete_mark_common ($) {
+        my ($argv) = @_;
+        # Workaround bash word-splitting URLs to ['https', ':', '//' ...]
+        # Maybe there's a better way to go about this in
+        # contrib/completion/lei-completion.bash
+        my $re = '';
+        my $cur = pop(@$argv) // '';
+        if (@$argv) {
+                my @x = @$argv;
+                if ($cur eq ':' && @x) {
+                        push @x, $cur;
+                        $cur = '';
+                }
+                while (@x > 2 && $x[0] !~ /\A[+\-](?:kw|L)\z/ &&
+                                        $x[1] ne ':') {
+                        shift @x;
+                }
+                if (@x >= 2) { # qw(kw : $KEYWORD) or qw(kw :)
+                        $re = join('', @x);
+                } else { # just return everything and hope for the best
+                        $re = join('', @$argv);
+                }
+                $re = quotemeta($re);
+        }
+        ($cur, $re);
+}
+
+# FIXME: same problems as _complete_forget_external and similar
+sub _complete_mark {
+        my ($self, @argv) = @_;
+        my @all = map { ("+kw:$_", "-kw:$_") } @KW;
+        return @all if !@argv;
+        my ($cur, $re) = _complete_mark_common(\@argv);
+        map {
+                # only return the part specified on the CLI
+                # don't duplicate if already 100% completed
+                /\A$re(\Q$cur\E.*)/ ? ($cur eq $1 ? () : $1) : ();
+        } grep(/$re\Q$cur/, @all);
+}
+
 1;