summaryrefslogtreecommitdiff
path: root/src/command_manager.cc
diff options
context:
space:
mode:
authorFrank LENORMAND <lenormf@gmail.com>2020-03-12 22:02:22 +0300
committerFrank LENORMAND <lenormf@gmail.com>2020-03-12 22:24:44 +0300
commit7b28e68d6cd3e60f5ff1a454ab52a4316d99b60a (patch)
tree5e10cfbf58756781a7ef9f35f658b7dfc24aadb9 /src/command_manager.cc
parent6766297623e9718db5b2b09bd655fe183acdcf67 (diff)
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'
Diffstat (limited to 'src/command_manager.cc')
-rw-r--r--src/command_manager.cc4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/command_manager.cc b/src/command_manager.cc
index e4b57de6..c2e5a8dd 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;