| 656 | * @returns The ShellConfiguration for the current environment. |
| 657 | */ |
| 658 | export function getShellConfiguration(): ShellConfiguration { |
| 659 | if (isWindows()) { |
| 660 | // -NonInteractive prevents PSReadLine from intercepting console input |
| 661 | // events inside the ConPTY session, which otherwise causes interactive |
| 662 | // TUI tools (e.g. pnpm create vite, vim) to receive malformed key events |
| 663 | // and exit when arrow keys are pressed. |
| 664 | const powershellArgsPrefix = ['-NoProfile', '-NonInteractive', '-Command']; |
| 665 | const comSpec = process.env['ComSpec']; |
| 666 | if (comSpec) { |
| 667 | const executable = comSpec.toLowerCase(); |
| 668 | if ( |
| 669 | executable.endsWith('powershell.exe') || |
| 670 | executable.endsWith('pwsh.exe') |
| 671 | ) { |
| 672 | return { |
| 673 | executable: comSpec, |
| 674 | argsPrefix: powershellArgsPrefix, |
| 675 | shell: 'powershell', |
| 676 | }; |
| 677 | } |
| 678 | } |
| 679 | |
| 680 | const pwshPath = resolveExecutable('pwsh.exe'); |
| 681 | if (pwshPath) { |
| 682 | return { |
| 683 | executable: pwshPath, |
| 684 | argsPrefix: ['-NoProfile', '-Command'], |
| 685 | shell: 'powershell', |
| 686 | }; |
| 687 | } |
| 688 | |
| 689 | // Fall back to Windows PowerShell 5.1 when pwsh.exe is not installed. |
| 690 | return { |
| 691 | executable: 'powershell.exe', |
| 692 | argsPrefix: powershellArgsPrefix, |
| 693 | shell: 'powershell', |
| 694 | }; |
| 695 | } |
| 696 | |
| 697 | // Unix-like systems (Linux, macOS) |
| 698 | return { executable: 'bash', argsPrefix: ['-c'], shell: 'bash' }; |
| 699 | } |
| 700 | |
| 701 | /** |
| 702 | * Export the platform detection constant for use in process management (e.g., killing processes). |