From c34f065076177f414f5328a85f675a40804d5c9f Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Thu, 21 Jan 2021 19:46:24 +0000 Subject: lei forget-external: bash completion support The tricky bit was getting around word splitting bash does on URLs. This may work with other shells, too. --- lib/PublicInbox/LeiExternal.pm | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'lib/PublicInbox/LeiExternal.pm') diff --git a/lib/PublicInbox/LeiExternal.pm b/lib/PublicInbox/LeiExternal.pm index 21071058..59c3c367 100644 --- a/lib/PublicInbox/LeiExternal.pm +++ b/lib/PublicInbox/LeiExternal.pm @@ -93,4 +93,21 @@ sub lei_forget_external { } } +# shell completion helper called by lei__complete +sub _complete_forget_external { + my ($self, @argv) = @_; + my $cfg = $self->_lei_cfg(0); + my $cur = pop @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 $colon = ($argv[-1] // '') eq ':'; + my $re = $cur =~ /\A[\w-]/ ? '' : '.*'; + map { + my $x = substr($_, length('external.')); + # only return the part specified on the CLI + $colon && $x =~ /(\Q$cur\E.*)/ ? $1 : $x; + } grep(/\Aexternal\.$re\Q$cur/, @{$cfg->{-section_order}}); +} + 1; -- cgit v1.2.3-24-ge0c7