> That message is a reflection of where things currently are. It contains a
> patch that will allow bash-completion to work unchanged. (In a nutshell,
> bash-completion makes assumptions about what compgen will do with quoted
> null arguments that changed between bash-4.2 and bash-4.3.)
>
> I think that patch will fix most, if not all, of the bash-completion
> problems. I need people to test it, since the platforms I commonly use
> for development (Mac OS X, RHEL) do not install bash-completion.
>
> For instance, I believe that the problem with these unquoted special
> characters is that they break words for readline, and readline passes
> an empty argument to the completion function as the word to be completed.
> I'm not sure what bash-completion does with that to make it include the
> previous word.
I've updated the patch, and attached it. This seems to fix all of the
reported problems from Debian's version of bash-completion. One thing
I have yet to do is to verify that other systems that ship bash-completion
have the same issues. If I cannot replicate the Debian-reported issues
on those systems, I will most likely not release this as an official
patch.
Chet
*** ../bash-4.3/externs.h 2014-01-02 14:58:20.000000000 -0500
--- externs.h 2014-03-13 14:42:57.000000000 -0400
***************
*** 325,328 ****
--- 325,329 ----
extern char *sh_backslash_quote_for_double_quotes __P((char *));
extern int sh_contains_shell_metas __P((char *));
+ extern int sh_contains_quotes __P((char *));
/* declarations for functions defined in lib/sh/spell.c */
*** ../bash-4.3/lib/sh/shquote.c 2013-03-31 21:53:32.000000000 -0400
--- lib/sh/shquote.c 2014-03-13 14:42:57.000000000 -0400
***************
*** 312,313 ****
--- 312,327 ----
return (0);
}
+
+ int
+ sh_contains_quotes (string)
+ char *string;
+ {
+ char *s;
+
+ for (s = string; s && *s; s++)
+ {
+ if (*s == '\'' || *s == '"' || *s == '\\')
+ return 1;
+ }
+ return 0;
+ }
*** ../bash-4.3/pcomplete.c 2013-08-26 15:23:45.000000000 -0400
--- pcomplete.c 2014-03-17 09:10:40.000000000 -0400
***************
*** 184,187 ****
--- 184,188 ----
COMPSPEC *pcomp_curcs;
const char *pcomp_curcmd;
+ const char *pcomp_curtxt;
#ifdef DEBUG
***************
*** 754,757 ****
--- 755,783 ----
dfn = (*rl_filename_dequoting_function) ((char *)text,
rl_completion_quote_character);
}
+ /* Intended to solve a mismatched assumption by bash-completion. If
+ the text to be completed is empty, but bash-completion turns it into
+ a quoted string ('') assuming that this code will dequote it before
+ calling readline, do the dequoting. */
+ else if (iscompgen && iscompleting &&
+ pcomp_curtxt && *pcomp_curtxt == 0 &&
+ text && (*text == '\'' || *text == '"') && text[1] == text[0] &&
text[2] == 0 &&
+ rl_filename_dequoting_function)
+ dfn = (*rl_filename_dequoting_function) ((char *)text,
rl_completion_quote_character);
+ /* Another mismatched assumption by bash-completion. If compgen is
being
+ run as part of bash-completion, and the argument to compgen is
not
+ the same as the word originally passed to the programmable
completion
+ code, dequote the argument if it has quote characters. It's an
+ attempt to detect when bash-completion is quoting its filename
+ argument before calling compgen. */
+ /* We could check whether gen_shell_function_matches is in the call
+ stack by checking whether the gen-shell-function-matches tag is in
+ the unwind-protect stack, but there's no function to do that yet.
+ We could simply check whether we're executing in a function by
+ checking variable_context, and may end up doing that. */
+ else if (iscompgen && iscompleting && rl_filename_dequoting_function &&
+ pcomp_curtxt && text &&
+ STREQ (pcomp_curtxt, text) == 0 &&
+ sh_contains_quotes (text)) /* guess */
+ dfn = (*rl_filename_dequoting_function) ((char *)text,
rl_completion_quote_character);
else
dfn = savestring (text);
***************
*** 1523,1527 ****
{
COMPSPEC *cs, *oldcs;
! const char *oldcmd;
STRINGLIST *ret;
--- 1549,1553 ----
{
COMPSPEC *cs, *oldcs;
! const char *oldcmd, *oldtxt;
STRINGLIST *ret;
***************
*** 1546,1552 ****
--- 1572,1580 ----
oldcs = pcomp_curcs;
oldcmd = pcomp_curcmd;
+ oldtxt = pcomp_curtxt;
pcomp_curcs = cs;
pcomp_curcmd = cmd;
+ pcomp_curtxt = word;
ret = gen_compspec_completions (cs, cmd, word, start, end, foundp);
***************
*** 1554,1557 ****
--- 1582,1586 ----
pcomp_curcs = oldcs;
pcomp_curcmd = oldcmd;
+ pcomp_curtxt = oldtxt;
/* We need to conditionally handle setting *retryp here */
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU [email protected] http://cnswww.cns.cwru.edu/~chet/