@@ -4803,15 +4803,24 @@ fn shell(cx: &mut compositor::Context, cmd: &str, behavior: &ShellBehavior) {
48034803 let mut ranges = SmallVec::with_capacity(selection.len());
48044804 let text = doc.text().slice(..);
48054805
4806+ let mut shell_output: Option<Tendril> = None;
48064807 let mut offset = 0isize;
4807−
48084808 for range in selection.ranges() {
4809− let fragment = range.slice(text);
4810− let (output, success) = match shell_impl(shell, cmd, pipe.then(|| fragment.into())) {
4811− Ok(result) => result,
4812− Err(err) => {
4813− cx.editor.set_error(err.to_string());
4814− return;
4809+ let (output, success) = if let Some(output) = shell_output.as_ref() {
4810+ (output.clone(), true)
4811+ } else {
4812+ let fragment = range.slice(text);
4813+ match shell_impl(shell, cmd, pipe.then(|| fragment.into())) {
4814+ Ok(result) => {
4815+ if !pipe {
4816+ shell_output = Some(result.0.clone());
4817+ }
4818+ result
4819+ }
4820+ Err(err) => {
4821+ cx.editor.set_error(err.to_string());
4822+ return;
4823+ }
48154824 }
48164825 };
48174826