From 471c75d7388c5b1bb0f59c7f257d6888e88c88bf Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Sun, 19 Jun 2016 17:01:56 +0100 Subject: [PATCH] Trim trailing end of lines in %sh outputs Fixes #698 --- src/command_manager.cc | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/command_manager.cc b/src/command_manager.cc index dafdc11d..7419e0bc 100644 --- a/src/command_manager.cc +++ b/src/command_manager.cc @@ -7,6 +7,7 @@ #include "shell_manager.hh" #include "utils.hh" #include "optional.hh" +#include "containers.hh" #include @@ -250,9 +251,22 @@ String expand_token(const Token& token, const Context& context, switch (token.type()) { case Token::Type::ShellExpand: - return ShellManager::instance().eval(content, context, {}, - ShellManager::Flags::WaitForStdout, - shell_context).first; + { + auto str = ShellManager::instance().eval( + content, context, {}, ShellManager::Flags::WaitForStdout, + shell_context).first; + + int trailing_eol_count = 0; + for (auto c : str | reverse()) + { + if (c != '\n') + break; + ++trailing_eol_count; + } + str.resize(str.length() - trailing_eol_count, 0); + return str; + + } case Token::Type::RegisterExpand: return context.main_sel_register_value(content).str(); case Token::Type::OptionExpand: