terminal: Fix escaping arguments when using CMD as the shell (#39701)

A couple of caveats:
- We should not auto-escape arguments with Alacritty's `escape_args`
option if using CMD otherwise, the generated command will have way too
many escaped characters for CMD to parse correctly.
- When composing a full command for CMD, we need to put it in double
quotes manually: `cmd /C "activate.bat& pwsh.exe -C do_something"` so
that CMD executes the entire string as a sequence of commands.
- CMD requires `&` as a chaining operator for commands (`;` for other
shells).

Release Notes:

- N/A
This commit is contained in:
Jakub Konka
2025-10-08 16:44:04 +00:00
committed by GitHub
parent 578e7e4cbd
commit 4684d6b50e
8 changed files with 48 additions and 19 deletions
+1 -1
View File
@@ -49,7 +49,7 @@ impl ShellBuilder {
format!("{} -C '{}'", self.program, command_to_use_in_label)
}
ShellKind::Cmd => {
format!("{} /C '{}'", self.program, command_to_use_in_label)
format!("{} /C \"{}\"", self.program, command_to_use_in_label)
}
ShellKind::Posix
| ShellKind::Nushell
+9
View File
@@ -345,6 +345,7 @@ impl Shell {
Shell::System => get_system_shell(),
}
}
pub fn program_and_args(&self) -> (String, &[String]) {
match self {
Shell::Program(program) => (program.clone(), &[]),
@@ -352,6 +353,14 @@ impl Shell {
Shell::System => (get_system_shell(), &[]),
}
}
pub fn shell_kind(&self) -> ShellKind {
match self {
Shell::Program(program) => ShellKind::new(program),
Shell::WithArguments { program, .. } => ShellKind::new(program),
Shell::System => ShellKind::system(),
}
}
}
type VsCodeEnvVariable = String;