(rawShellPath: string)
| 13 | } |
| 14 | |
| 15 | export async function validateTerminalShellPath(rawShellPath: string): Promise<TerminalShellValidationResult> { |
| 16 | const shellPath = rawShellPath.trim() |
| 17 | |
| 18 | if (!shellPath) { |
| 19 | return { valid: false, reason: "shell path cannot be empty" } |
| 20 | } |
| 21 | |
| 22 | if (!path.isAbsolute(shellPath)) { |
| 23 | return { valid: false, reason: "shell path must be absolute" } |
| 24 | } |
| 25 | |
| 26 | try { |
| 27 | const stats = await fs.stat(shellPath) |
| 28 | |
| 29 | if (!stats.isFile()) { |
| 30 | return { valid: false, reason: "shell path must point to a file" } |
| 31 | } |
| 32 | |
| 33 | if (process.platform !== "win32") { |
| 34 | await fs.access(shellPath, fsConstants.X_OK) |
| 35 | } |
| 36 | } catch { |
| 37 | return { |
| 38 | valid: false, |
| 39 | reason: |
| 40 | process.platform === "win32" |
| 41 | ? "shell path does not exist or is not a file" |
| 42 | : "shell path does not exist, is not a file, or is not executable", |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | return { valid: true, shellPath } |
| 47 | } |
no test coverage detected