bug-bash
[Top][All Lists]
Advanced

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

[PATCH] Fix custom program's completions when initial word is set


From: Luca Boccassi
Subject: [PATCH] Fix custom program's completions when initial word is set
Date: Fri, 23 Nov 2018 12:48:54 +0000

The change to fix mid-word initial completion inadvertently broke custom
command completion.
To reproduce:

cat > repro<<EOF
_repro()
{
  echo "completed"
}
EOF
source repro
complete -I -F _repro
git sho
      ^ tab, nothing happens

This is because if complete -I is set, iw_compspec will always be
non-null and therefore foundcs will always be set to false and bash
will ignore the result of programmable_completions().
The fix is to only override foundcs if both iw_compspec is not null
and we are not in command position.

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

noticed this a bit too late after some more testing. This fix appears
to work, let me know if you'd like a different solution.
Thanks!

 bashline.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/bashline.c b/bashline.c
index d56cd79d..f2d17a70 100644
--- a/bashline.c
+++ b/bashline.c
@@ -1583,7 +1583,7 @@ attempt_shell_completion (text, start, end)
          /* command completion if programmable completion fails */
          /* If we have a completion for the initial word, we can prefer that */
          in_command_position = s == start && (iw_compspec || STREQ (n, text)); 
/* XXX */
-         foundcs = foundcs && (iw_compspec == 0);
+         foundcs = foundcs && (iw_compspec == 0 || in_command_position == 0);
        }
       /* empty command name following command separator */
       else if (s >= e && n[0] == '\0' && text[0] == '\0' && start > 0 &&
-- 
2.19.1




reply via email to

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