Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #14790

[PATCH] initial word completion: fix completion of prefix

Path csiph.com!xmission!news.snarked.org!news.linkpendium.com!news.linkpendium.com!panix!usenet.stanford.edu!not-for-mail
From Luca Boccassi <bluca@debian.org>
Newsgroups gnu.bash.bug
Subject [PATCH] initial word completion: fix completion of prefix
Date Fri, 9 Nov 2018 18:52:17 +0000
Lines 65
Approved bug-bash@gnu.org
Message-ID <mailman.3761.1541789558.1284.bug-bash@gnu.org> (permalink)
NNTP-Posting-Host lists.gnu.org
Mime-Version 1.0
Content-Transfer-Encoding 8bit
X-Trace usenet.stanford.edu 1541789559 18130 208.118.235.17 (9 Nov 2018 18:52:39 GMT)
X-Complaints-To action@cs.stanford.edu
Cc Luca Boccassi <bluca@debian.org>
To bug-bash@gnu.org
Envelope-to bug-bash@gnu.org
X-Google-DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=+Fv7jZDNkrol46gcJaO6quZY0YTyje0djMwbqxd/MdU=; b=uODtBA2izSoM38IkrDBomOdt1aUgKikhrwAmlUUTkGVh537e4Hs35d9IHTjny7cVYj 6ribHmJBoYgRBd9Je6aN0PPg1uwekaTWLHAHnXM3wJ04oBOh5xLXQVprdfc/OscvgWee p5kBinUtAccNBNAeYf0/RFvomyCIz0OpTqOurjLmLjYIQ9TQ22fMgd4K3d//Lauu0Djn 1FF6A3OCR+sKKuucUu7XBCJz7W54uDqVcCvC1TkCMKQaZCs8CiG1tAyA36wpF9c1zl+l Wl4GZ7uDiSY0B9Gxpom4fjZ4WmOhlqoRrCq+DIcKeszuLKGnzARHrPfSbW2Utue6LaI1 ZduQ==
X-Gm-Message-State AGRZ1gL0SRqFBA6MaSCTiY0EAw32EH6SUJM2dbeU2amZ00Q1LKi4N5Ww MxGkT1dwcUOlMUX7s3tnDkxxktcL
X-Google-Smtp-Source AJdET5eFX6MqImFi4+igzc2mmU+meyb46bbBy3QopHEStPNsOpCDsV0mLaaT4nhP/mK/zlz//ClVOw==
X-Received by 2002:a5d:6b43:: with SMTP id x3-v6mr6864498wrw.304.1541789541956; Fri, 09 Nov 2018 10:52:21 -0800 (PST)
X-Mailer git-send-email 2.19.1
X-detected-operating-system by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy]
X-Received-From 209.85.221.68
X-BeenThere bug-bash@gnu.org
X-Mailman-Version 2.1.21
Precedence list
List-Id Bug reports for the GNU Bourne Again SHell <bug-bash.gnu.org>
List-Unsubscribe <https://lists.gnu.org/mailman/options/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=unsubscribe>
List-Archive <http://lists.gnu.org/archive/html/bug-bash/>
List-Post <mailto:bug-bash@gnu.org>
List-Help <mailto:bug-bash-request@gnu.org?subject=help>
List-Subscribe <https://lists.gnu.org/mailman/listinfo/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=subscribe>
Xref csiph.com gnu.bash.bug:14790

Show key headers only | View raw


If the user types:

gcfile.c

And positions the cursor of 'f', a programmable completion enabled on
initial word (-I) will fail to run. This is because the parsing gives
priority first to the _minimal programmable completion that does
nothing, and then if that is disabled it gives the next priority to
command completion, unlike what happens when completing a full word,
stopping the initial word completion from working.

To reproduce:

cat > repro<<EOF
_repro()
{
  echo "completed"
}
EOF
source repro
complete -I -F _repro
lsfile
  ^ tab with cursor on 'f', nothing happens
complete -r -F _minimal
lsfile
  ^ tab with cursor on 'f', command completion happens

To fix this issue, if iw_compspec is defined (initial word completion
is enabled) allow to complete a prefix of the entered text and skip
command completion.

Signed-off-by: Luca Boccassi <bluca@debian.org>
---

Dear maintainer,

This is the simplest and cleanest solution I could find. I'm happy to
test alternative bug fixes if necessary.
Thanks!

 bashline.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/bashline.c b/bashline.c
index 0d39714f..83ef3fa8 100644
--- a/bashline.c
+++ b/bashline.c
@@ -1580,8 +1580,11 @@ attempt_shell_completion (text, start, end)
       else if (e > s && was_assignment == 0 && have_progcomps)
 	{
 	  prog_complete_matches = programmable_completions (n, text, s, e, &foundcs);
-	  /* command completion if programmable completion fails */
-	  in_command_position = s == start && STREQ (n, text);	/* XXX */
+	  /* command completion if programmable completion fails.
+	     Initial word completion can be done on prefix: gcfile.c -> gcc file.c
+	     when tabbing with cursor on 'f' and needs to have precedence over cmd completion. */
+	  in_command_position = s == start && (iw_compspec || STREQ (n, text));	/* XXX */
+	  foundcs = foundcs && !iw_compspec;
 	}
       /* empty command name following command separator */
       else if (s >= e && n[0] == '\0' && text[0] == '\0' && start > 0 &&
-- 
2.19.1

Back to gnu.bash.bug | Previous | Next | Find similar | Unroll thread


Thread

[PATCH] initial word completion: fix completion of prefix Luca Boccassi <bluca@debian.org> - 2018-11-09 18:52 +0000

csiph-web