Roo-Code/apps/cli/src/lib/utils/shell.ts
John Richmond 7dc83a522e
Allow selecting a specific shell (#11851)
* Allow selecting a specific shell

Add --terminal-shell CLI flag to specify which shell ExecaTerminalProcess
uses for inline command execution. The shell path is validated at the CLI
layer and passed through the standard settings mechanism (BaseTerminal
static getter/setter), matching how all other CLI terminal settings flow
through the system.

* test(cli): make shell path access test cross-platform
2026-03-03 23:31:34 -08:00

47 lines
1 KiB
TypeScript

import fs from "fs/promises"
import { constants as fsConstants } from "fs"
import path from "path"
export type TerminalShellValidationResult =
| {
valid: true
shellPath: string
}
| {
valid: false
reason: string
}
export async function validateTerminalShellPath(rawShellPath: string): Promise<TerminalShellValidationResult> {
const shellPath = rawShellPath.trim()
if (!shellPath) {
return { valid: false, reason: "shell path cannot be empty" }
}
if (!path.isAbsolute(shellPath)) {
return { valid: false, reason: "shell path must be absolute" }
}
try {
const stats = await fs.stat(shellPath)
if (!stats.isFile()) {
return { valid: false, reason: "shell path must point to a file" }
}
if (process.platform !== "win32") {
await fs.access(shellPath, fsConstants.X_OK)
}
} catch {
return {
valid: false,
reason:
process.platform === "win32"
? "shell path does not exist or is not a file"
: "shell path does not exist, is not a file, or is not executable",
}
}
return { valid: true, shellPath }
}