* Check if a shell is available on the system
(shellPath)
| 32 | * Check if a shell is available on the system |
| 33 | */ |
| 34 | async function isShellAvailable(shellPath) { |
| 35 | try { |
| 36 | // For Windows shells, use different detection methods |
| 37 | if (shellPath === 'cmd' || shellPath === 'cmd.exe') { |
| 38 | // On Windows, cmd should always be available |
| 39 | if (os.platform() === 'win32') { |
| 40 | return true; |
| 41 | } |
| 42 | return false; |
| 43 | } |
| 44 | |
| 45 | if (shellPath === 'pwsh' || shellPath === 'powershell') { |
| 46 | // Check if PowerShell is available |
| 47 | try { |
| 48 | const result = await executeCommand(`${shellPath} -Command "Get-Host"`, 2000); |
| 49 | return result.content && result.content[0] && !result.content[0].text.includes('not found'); |
| 50 | } catch (error) { |
| 51 | return false; |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | // For Unix shells, check if the file exists and is executable |
| 56 | try { |
| 57 | const result = await executeCommand(`test -x "${shellPath}" && echo "available"`, 2000); |
| 58 | return result.content && result.content[0] && result.content[0].text.includes('available'); |
| 59 | } catch (error) { |
| 60 | return false; |
| 61 | } |
| 62 | } catch (error) { |
| 63 | console.log(`Could not check availability of ${shellPath}: ${error.message}`); |
| 64 | return false; |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * Get expected shell output for a given shell path |
no test coverage detected