Skip to content

Commit

Permalink
fix(commands): change pipe-like output trimming (helix-editor#11183)
Browse files Browse the repository at this point in the history
  • Loading branch information
RoloEdits authored and kyruzic committed Sep 27, 2024
1 parent 392923f commit 5278a1a
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit 5278a1a

Please sign in to comment.