[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] initial word completion: fix completion of prefix

From: Luca Boccassi
Subject: [PATCH] initial word completion: fix completion of prefix
Date: Fri, 9 Nov 2018 18:52:17 +0000

If the user types:


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
  echo "completed"
source repro
complete -I -F _repro
  ^ tab with cursor on 'f', nothing happens
complete -r -F _minimal
  ^ 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 <address@hidden>

Dear maintainer,

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

 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, 
-         /* 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 
+            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 &&

reply via email to

[Prev in Thread] Current Thread [Next in Thread]