fix(non-interactive-env): detect shell type for csh/tcsh env var syntax (fixes #2089)

This commit is contained in:
MoerAI
2026-03-23 19:33:54 +09:00
parent 331f7ec52b
commit 92509d8cfb
2 changed files with 17 additions and 5 deletions
+13 -1
View File
@@ -1,4 +1,4 @@
export type ShellType = "unix" | "powershell" | "cmd"
export type ShellType = "unix" | "powershell" | "cmd" | "csh"
/**
* Detect the current shell type based on environment variables.
@@ -14,6 +14,10 @@ export function detectShellType(): ShellType {
}
if (process.env.SHELL) {
const shell = process.env.SHELL
if (shell.includes("csh") || shell.includes("tcsh")) {
return "csh"
}
return "unix"
}
@@ -34,6 +38,7 @@ export function shellEscape(value: string, shellType: ShellType): string {
switch (shellType) {
case "unix":
case "csh":
if (/[^a-zA-Z0-9_\-.:\/]/.test(value)) {
return `'${value.replace(/'/g, "'\\''")}'`
}
@@ -91,6 +96,13 @@ export function buildEnvPrefix(
return `export ${assignments};`
}
case "csh": {
const assignments = entries
.map(([key, value]) => `setenv ${key} ${shellEscape(value, shellType)}`)
.join("; ")
return `${assignments};`
}
case "powershell": {
const assignments = entries
.map(([key, value]) => `$env:${key}=${shellEscape(value, shellType)}`)