From 535351067c2ac018ee2fef6cc685f49065617bd1 Mon Sep 17 00:00:00 2001 From: RoloEdits Date: Mon, 15 Jul 2024 20:29:44 -0700 Subject: [PATCH] fix(commands): change `pipe`-like output trimming (#11183) --- helix-term/src/commands.rs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 234902886..7e0bee92b 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -5745,14 +5745,20 @@ fn shell(cx: &mut compositor::Context, cmd: &str, behavior: &ShellBehavior) { let output = if let Some(output) = shell_output.as_ref() { output.clone() } else { - let fragment = range.slice(text); - match shell_impl(shell, cmd, pipe.then(|| fragment.into())) { - Ok(result) => { - let result = Tendril::from(result.trim_end()); + let input = range.slice(text); + match shell_impl(shell, cmd, pipe.then(|| input.into())) { + Ok(mut output) => { + if !input.ends_with("\n") && !output.is_empty() && output.ends_with('\n') { + output.pop(); + if output.ends_with('\r') { + output.pop(); + } + } + if !pipe { - shell_output = Some(result.clone()); + shell_output = Some(output.clone()); } - result + output } Err(err) => { cx.editor.set_error(err.to_string());