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.

agent: Fix shell hang on shell syntax errors with terminal tool usage (#59270)

procr1337c578f4d12b94
diff --git a/crates/util/src/shell_builder.rs b/crates/util/src/shell_builder.rs
index 58857ab2f61..dd2497a29ef 100644
--- a/crates/util/src/shell_builder.rs
+++ b/crates/util/src/shell_builder.rs
@@ -99,12 +99,10 @@ impl ShellBuilder {
});
if self.redirect_stdin {
match self.kind {
- ShellKind::Fish => {
- combined_command.insert_str(0, "begin; ");
- combined_command.push_str("; end </dev/null");
+ ShellKind::Fish | ShellKind::Posix => {
+ combined_command.insert_str(0, "exec </dev/null; ");
}
- ShellKind::Posix
- | ShellKind::Nushell
+ ShellKind::Nushell
| ShellKind::Csh
| ShellKind::Tcsh
| ShellKind::Rc
@@ -145,12 +143,10 @@ impl ShellBuilder {
});
if self.redirect_stdin {
match self.kind {
- ShellKind::Fish => {
- combined_command.insert_str(0, "begin; ");
- combined_command.push_str("; end </dev/null");
+ ShellKind::Fish | ShellKind::Posix => {
+ combined_command.insert_str(0, "exec </dev/null; ");
}
- ShellKind::Posix
- | ShellKind::Nushell
+ ShellKind::Nushell
| ShellKind::Csh
| ShellKind::Tcsh
| ShellKind::Rc
@@ -286,7 +282,7 @@ mod test {
.build(Some("echo".into()), &["test".to_string()]);
assert_eq!(program, "fish");
- assert_eq!(args, vec!["-i", "-c", "begin; echo test; end </dev/null"]);
+ assert_eq!(args, vec!["-i", "-c", "exec </dev/null; echo test"]);
}
#[test]
@@ -302,7 +298,7 @@ mod test {
assert_eq!(program, "sh");
assert_eq!(
args,
- vec!["-i", "-c", "(cat <<EOF\nhello\nEOF\n) </dev/null"]
+ vec!["-i", "-c", "exec </dev/null; cat <<EOF\nhello\nEOF"]
);
}