MCPcopy
hub / github.com/Fission-AI/OpenSpec / detectShell

Function detectShell

src/utils/shell-detection.ts:21–62  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

19 * @returns Detection result with supported shell and raw detected name
20 */
21export function detectShell(): ShellDetectionResult {
22 // Try SHELL environment variable first (Unix-like systems)
23 const shellPath = process.env.SHELL;
24
25 if (shellPath) {
26 const shellName = shellPath.toLowerCase();
27
28 if (shellName.includes('zsh')) {
29 return { shell: 'zsh', detected: 'zsh' };
30 }
31 if (shellName.includes('bash')) {
32 return { shell: 'bash', detected: 'bash' };
33 }
34 if (shellName.includes('fish')) {
35 return { shell: 'fish', detected: 'fish' };
36 }
37
38 // Shell detected but not supported
39 // Extract shell name from path (e.g., /bin/tcsh -> tcsh)
40 const match = shellPath.match(/\/([^/]+)$/);
41 const detectedName = match ? match[1] : shellPath;
42 return { shell: undefined, detected: detectedName };
43 }
44
45 // Check for PowerShell on Windows
46 // PSModulePath is a reliable PowerShell-specific environment variable
47 if (process.env.PSModulePath || process.platform === 'win32') {
48 const comspec = process.env.COMSPEC?.toLowerCase();
49
50 // If PSModulePath exists, we're definitely in PowerShell
51 if (process.env.PSModulePath) {
52 return { shell: 'powershell', detected: 'powershell' };
53 }
54
55 // On Windows without PSModulePath, we might be in cmd.exe
56 if (comspec?.includes('cmd.exe')) {
57 return { shell: undefined, detected: 'cmd.exe' };
58 }
59 }
60
61 return { shell: undefined, detected: undefined };
62}

Callers 2

resolveShellOrExitMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected