(shell: string, mode: "-il" | "-l")
| 34 | } |
| 35 | |
| 36 | function probe(shell: string, mode: "-il" | "-l"): Probe { |
| 37 | const out = spawnSync(shell, [mode, "-c", "env -0"], { |
| 38 | stdio: ["ignore", "pipe", "ignore"], |
| 39 | timeout: TIMEOUT, |
| 40 | windowsHide: true, |
| 41 | }) |
| 42 | |
| 43 | const err = out.error as NodeJS.ErrnoException | undefined |
| 44 | if (err) { |
| 45 | if (err.code === "ETIMEDOUT") return { type: "Timeout" } |
| 46 | console.log(`[server] Shell env probe failed for ${shell} ${mode}: ${err.message}`) |
| 47 | return { type: "Unavailable" } |
| 48 | } |
| 49 | |
| 50 | if (out.status !== 0) { |
| 51 | console.log(`[server] Shell env probe exited with non-zero status for ${shell} ${mode}`) |
| 52 | return { type: "Unavailable" } |
| 53 | } |
| 54 | |
| 55 | const env = parseShellEnv(out.stdout) |
| 56 | if (Object.keys(env).length === 0) { |
| 57 | console.log(`[server] Shell env probe returned empty env for ${shell} ${mode}`) |
| 58 | return { type: "Unavailable" } |
| 59 | } |
| 60 | |
| 61 | return { type: "Loaded", value: env } |
| 62 | } |
| 63 | |
| 64 | export function isNushell(shell: string) { |
| 65 | const name = basename(shell).toLowerCase() |
no test coverage detected