Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

util: Fix stdin redirect for ShellBuilder (#62078)

procr13378e18ab0cd7cd
diff --git a/crates/util/src/shell_builder.rs b/crates/util/src/shell_builder.rs
index 57ce0319a40..76ff3923e62 100644
--- a/crates/util/src/shell_builder.rs
+++ b/crates/util/src/shell_builder.rs
@@ -99,8 +99,17 @@ impl ShellBuilder {
});
if self.redirect_stdin {
match self.kind {
- ShellKind::Fish | ShellKind::Posix => {
- combined_command.insert_str(0, "exec </dev/null; ");
+ ShellKind::Posix => {
+ // Perform the STDIN redirection prior to the actual
+ // command on a separate line, so that it is already
+ // active if the command contains a syntax error.
+ // Otherwise, with -i, dash will fall back to an
+ // interactive shell in this case.
+ combined_command.insert_str(0, "exec </dev/null\n");
+ }
+ ShellKind::Fish => {
+ combined_command.insert_str(0, "begin; ");
+ combined_command.push_str("; end </dev/null");
}
ShellKind::Nushell
| ShellKind::Csh
@@ -143,8 +152,12 @@ impl ShellBuilder {
});
if self.redirect_stdin {
match self.kind {
- ShellKind::Fish | ShellKind::Posix => {
- combined_command.insert_str(0, "exec </dev/null; ");
+ ShellKind::Posix => {
+ combined_command.insert_str(0, "exec </dev/null\n");
+ }
+ ShellKind::Fish => {
+ combined_command.insert_str(0, "begin; ");
+ combined_command.push_str("; end </dev/null");
}
ShellKind::Nushell
| ShellKind::Csh
@@ -282,7 +295,7 @@ mod test {
.build(Some("echo".into()), &["test".to_string()]);
assert_eq!(program, "fish");
- assert_eq!(args, vec!["-i", "-c", "exec </dev/null; echo test"]);
+ assert_eq!(args, vec!["-i", "-c", "begin; echo test; end </dev/null"]);
}
#[test]
@@ -298,7 +311,7 @@ mod test {
assert_eq!(program, "sh");
assert_eq!(
args,
- vec!["-i", "-c", "exec </dev/null; cat <<EOF\nhello\nEOF"]
+ vec!["-i", "-c", "exec </dev/null\ncat <<EOF\nhello\nEOF"]
);
}