From 7b28e68d6cd3e60f5ff1a454ab52a4316d99b60a Mon Sep 17 00:00:00 2001 From: Frank LENORMAND Date: Thu, 12 Mar 2020 22:02:22 +0300 Subject: [PATCH] src: Don't escape completion candidates with `\` Completion candidates are currently escaped with a backslash `\` character, which leads to ugly interactive commands on the prompt, especially when they contain space characters. This commit makes completion candidates be escaped by simple quoting. Examples: candidate\ with\ spaces \%opt{foo} \"dquote \'quote become: 'candidate with spaces' '%opt{foo}' '"dquote' '''quote' --- src/command_manager.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/command_manager.cc b/src/command_manager.cc index e4b57de61..c2e5a8dd8 100644 --- a/src/command_manager.cc +++ b/src/command_manager.cc @@ -758,7 +758,9 @@ Completions CommandManager::complete(const Context& context, if (not (completions.flags & Completions::Flags::Quoted) and token.type == Token::Type::Raw) { for (auto& c : completions.candidates) - c = (not c.empty() and contains("%'\"", c[0]) ? "\\" : "") + escape(c, "; \t", '\\'); + c = (not c.empty() and c[0] == '%') or + any_of(c, [](auto i) { return contains("; \t'\"", i); }) ? + format("'{}'", replace(c, "'", "''")) : c; } return completions;