Skip to content

Commit 95feefc

Browse files
authored
remote: Fix terminal crash on Elvish shell (zed-industries#41893)
1 parent a827f25 commit 95feefc

4 files changed

Lines changed: 49 additions & 10 deletions

File tree

‎crates/languages/src/python.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,6 +1217,7 @@ impl ToolchainLister for PythonToolchainProvider {
12171217
ShellKind::Cmd => None,
12181218
ShellKind::Rc => None,
12191219
ShellKind::Xonsh => None,
1220+
ShellKind::Elvish => None,
12201221
})
12211222
}
12221223
_ => {}

‎crates/util/src/shell.rs‎

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ pub enum ShellKind {
6060
Nushell,
6161
Cmd,
6262
Xonsh,
63+
Elvish,
6364
}
6465

6566
pub fn get_system_shell() -> String {
@@ -216,6 +217,7 @@ impl fmt::Display for ShellKind {
216217
ShellKind::Cmd => write!(f, "cmd"),
217218
ShellKind::Rc => write!(f, "rc"),
218219
ShellKind::Xonsh => write!(f, "xonsh"),
220+
ShellKind::Elvish => write!(f, "elvish"),
219221
}
220222
}
221223
}
@@ -241,6 +243,7 @@ impl ShellKind {
241243
"tcsh" => ShellKind::Tcsh,
242244
"rc" => ShellKind::Rc,
243245
"xonsh" => ShellKind::Xonsh,
246+
"elvish" => ShellKind::Elvish,
244247
"sh" | "bash" | "zsh" => ShellKind::Posix,
245248
_ if is_windows => ShellKind::PowerShell,
246249
// Some other shell detected, the user might install and use a
@@ -260,6 +263,7 @@ impl ShellKind {
260263
Self::Rc => input.to_owned(),
261264
Self::Nushell => Self::to_nushell_variable(input),
262265
Self::Xonsh => input.to_owned(),
266+
Self::Elvish => input.to_owned(),
263267
}
264268
}
265269

@@ -386,7 +390,8 @@ impl ShellKind {
386390
| ShellKind::Csh
387391
| ShellKind::Tcsh
388392
| ShellKind::Rc
389-
| ShellKind::Xonsh => interactive
393+
| ShellKind::Xonsh
394+
| ShellKind::Elvish => interactive
390395
.then(|| "-i".to_owned())
391396
.into_iter()
392397
.chain(["-c".to_owned(), combined_command])
@@ -404,7 +409,8 @@ impl ShellKind {
404409
| ShellKind::Rc
405410
| ShellKind::Fish
406411
| ShellKind::Cmd
407-
| ShellKind::Xonsh => None,
412+
| ShellKind::Xonsh
413+
| ShellKind::Elvish => None,
408414
}
409415
}
410416

@@ -427,7 +433,8 @@ impl ShellKind {
427433
| ShellKind::Fish
428434
| ShellKind::PowerShell
429435
| ShellKind::Nushell
430-
| ShellKind::Xonsh => ';',
436+
| ShellKind::Xonsh
437+
| ShellKind::Elvish => ';',
431438
}
432439
}
433440

@@ -441,7 +448,7 @@ impl ShellKind {
441448
| ShellKind::Fish
442449
| ShellKind::PowerShell
443450
| ShellKind::Xonsh => "&&",
444-
ShellKind::Nushell => ";",
451+
ShellKind::Nushell | ShellKind::Elvish => ";",
445452
}
446453
}
447454

@@ -457,7 +464,8 @@ impl ShellKind {
457464
| ShellKind::Rc
458465
| ShellKind::Fish
459466
| ShellKind::Nushell
460-
| ShellKind::Xonsh => arg,
467+
| ShellKind::Xonsh
468+
| ShellKind::Elvish => arg,
461469
})
462470
}
463471

@@ -511,7 +519,8 @@ impl ShellKind {
511519
| ShellKind::Tcsh
512520
| ShellKind::Posix
513521
| ShellKind::Rc
514-
| ShellKind::Xonsh => "source",
522+
| ShellKind::Xonsh
523+
| ShellKind::Elvish => "source",
515524
}
516525
}
517526

@@ -525,7 +534,8 @@ impl ShellKind {
525534
| ShellKind::Fish
526535
| ShellKind::PowerShell
527536
| ShellKind::Nushell
528-
| ShellKind::Xonsh => "clear",
537+
| ShellKind::Xonsh
538+
| ShellKind::Elvish => "clear",
529539
}
530540
}
531541

@@ -542,7 +552,8 @@ impl ShellKind {
542552
| ShellKind::Fish
543553
| ShellKind::PowerShell
544554
| ShellKind::Nushell
545-
| ShellKind::Xonsh => true,
555+
| ShellKind::Xonsh
556+
| ShellKind::Elvish => true,
546557
}
547558
}
548559
}

‎crates/util/src/shell_builder.rs‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ impl ShellBuilder {
5454
| ShellKind::Csh
5555
| ShellKind::Tcsh
5656
| ShellKind::Rc
57-
| ShellKind::Xonsh => {
57+
| ShellKind::Xonsh
58+
| ShellKind::Elvish => {
5859
let interactivity = self.interactive.then_some("-i ").unwrap_or_default();
5960
format!(
6061
"{PROGRAM} {interactivity}-c '{command_to_use_in_label}'",
@@ -93,7 +94,8 @@ impl ShellBuilder {
9394
| ShellKind::Csh
9495
| ShellKind::Tcsh
9596
| ShellKind::Rc
96-
| ShellKind::Xonsh => {
97+
| ShellKind::Xonsh
98+
| ShellKind::Elvish => {
9799
combined_command.insert(0, '(');
98100
combined_command.push_str(") </dev/null");
99101
}

‎crates/util/src/shell_env.rs‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,31 @@ async fn capture_windows(
172172
);
173173
output
174174
}
175+
ShellKind::Elvish => {
176+
let output = crate::command::new_smol_command(shell_path)
177+
.args([
178+
"-c",
179+
&format!(
180+
"cd '{}'; {} --printenv",
181+
directory.display(),
182+
zed_path.display()
183+
),
184+
])
185+
.stdin(Stdio::null())
186+
.stdout(Stdio::piped())
187+
.stderr(Stdio::piped())
188+
.output()
189+
.await?;
190+
191+
anyhow::ensure!(
192+
output.status.success(),
193+
"Elvish command failed with {}. stdout: {:?}, stderr: {:?}",
194+
output.status,
195+
String::from_utf8_lossy(&output.stdout),
196+
String::from_utf8_lossy(&output.stderr),
197+
);
198+
output
199+
}
175200
ShellKind::Nushell => {
176201
let output = crate::command::new_smol_command(shell_path)
177202
.args([

0 commit comments

Comments
 (0)