On Wed, Sep 19, 2012 at 08:23:01PM +0200, Felipe Contreras wrote: > >> Care to wrap it up in a patch? > > > > I'm trying to, but unfortunately "\n" gets converted to "\\n", so it > > doesn't get separated to words. Any ideas? > > Actually, this seems to do the trick: > > local words IFS=$'\n' > printf -v words "%q" "$1" > COMPREPLY=($(compgen -P "${2-}" -S "${4- }" -W "${words//\\n/$IFS}" > -- "${3-$cur}")) > > I don't know how to do $'\n' in the middle of double-quotes, but $IFS works. I don't think you can search-and-replace backslash-escaped characters and always get the correct result. For example, in this string: \\n Your regex would match the "\n", missing the context that the backslash is actually the second-half of an escaped pair. Searching for "[^\\]\\n" would similarly miss that: \\\n should be converted. IOW, I think backslash-escaping fundamentally has to either be parsed left-to-right, or quoted backslashes peeled in order (if I were not such a bad computer scientist, I could probably come up with some proof involving Chomsky's hierarchy of grammars). I think the real problem is that we are feeding "printf %q" an input where we want _most_ of the constructs quoted, but not some (namely newline, which is syntactically significant, and which we accept will break our completion). So something like the manual quoting I posted earlier in the thread is actually much closer to what we want. On a related note, I notice that even with either of our patches, doing this: echo content >'${foo.bar}' git add . git commit -m whatever git show HEAD:<tab> will yield this completion: git show HEAD:${foo.bar} which is correct, but not useful. It needs to be quoted _again_ to avoid interpolation when you actually quote the command. Bash's filename completion handles this automatically. E.g., if you do: git add <tab> you will get: git add \$\{foo.bar\} I have no idea if that internal to bash's filename completion, or if there is some easy facility offered to programmable completions to do the same thing. I don't think this is a high priority, but it would be nice to handle it. And moreover, I am really wondering if we are missing some solution that bash is providing to help us with the quoting issues. Surely we are not the first completion script to come up against this. -Peff -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html