From 8ec9c5f75200d7a54015cc3bd86cbe7a0836cc43 Mon Sep 17 00:00:00 2001 From: Guilhem Moulin Date: Fri, 20 Mar 2015 14:13:09 +0100 Subject: Determine the depth level of completion from the longest common prefix. --- icevault | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/icevault b/icevault index 45be1e0..eb073cb 100755 --- a/icevault +++ b/icevault @@ -224,7 +224,8 @@ sub sendCommand(@) { } # Get all identities with the given $prefix. If there are multiple -# matches and $all is false, limit the output to one depth. +# matches and $all is false, limit the output to one depth more than the +# longuest common prefix. sub complete($;$) { my $prefix = shift // ''; my $all = shift; @@ -283,8 +284,12 @@ sub complete($;$) { } return @matches if $all or $#matches < 1; - if ($prefix =~ /\A[A-Za-z0-9-]+:\/\/[^\P{Graph}:\/]+(?::\d+)?\//) { - } elsif ($prefix =~ /\A[A-Za-z0-9-]+:\/\//) { + # find the longest common prefix to determine the depth level of completion + my $p = $matches[0]; + do { chop $p until /\A\Q$p\E/ } foreach @matches; + + if ($p =~ /\A[A-Za-z0-9-]+:\/\/[^\P{Graph}:\/]+(?::\d+)?\//) { + } elsif ($p =~ /\A[A-Za-z0-9-]+:\/\//) { s#/[^\P{Print}\/]+\z#/# foreach @matches; } elsif (defined $s) { s#://[^\P{Graph}\/]+/[^\P{Print}\/]+\z#://# foreach @matches; -- cgit v1.2.3