-
Notifications
You must be signed in to change notification settings - Fork 85
Description
Describe the bug
The _shell() method in config.js fails to detect PowerShell 7 (pwsh) when running without administrator privileges on Windows, because it only checks if process.title contains "powershell" but not "pwsh".
When running a CLI built with oclif in PowerShell 7 without admin privileges:
- process.title is "pwsh" (or similar)
- The shell detection falls through to COMSPEC, returning "cmd.exe"
- This causes @oclif/plugin-autocomplete to not display PowerShell setup instructions
When running the same CLI in PowerShell 7 with admin privileges:
- process.title includes "PowerShell" (e.g., "Administrator: PowerShell 7")
- Shell is correctly detected as "powershell"
- Autocomplete instructions display correctly
To Reproduce
- Open PowerShell 7 (pwsh) without admin privileges on Windows
- Run
node -e "console.log(process.title)", outputs pwsh or similar (not containing "powershell") - Run any oclif CLI with the autocomplete plugin (e.g., mycli autocomplete)
- Observe that PowerShell-specific instructions are not shown
$ mycli autocomplete Building the autocomplete cache... done Setup Instructions for MyCli CLI Autocomplete --- ============================================== Every time you enter <TAB>, the autocomplete feature displays a list of commands (or flags if you type --), along with their summaries. Enter a letter and then <TAB> again to narrow down the list until you end up with the complete command that you want to execute. Enjoy!
- Open PowerShell 7 as Administrator
- Run
node -e "console.log(process.title)", outputs something containing "PowerShell" - Run the same autocomplete command
- Observe that PowerShell instructions are now shown correctly
$ mycli autocomplete Building the autocomplete cache... done Setup Instructions for MyCli CLI Autocomplete --- ============================================== 1) Run these two cmdlets in your PowerShell window in the order shown: New-Item -Type Directory -Path (Split-Path -Parent $PROFILE) -ErrorAction SilentlyContinue Add-Content -Path $PROFILE -Value (Invoke-Expression -Command "mycli autocomplete script powershell"); .$PROFILE 2) (Optional) If you want matching completions printed below the command line, run this cmdlet: Set-PSReadlineKeyHandler -Key Tab -Function MenuComplete 3) Start using autocomplete: mycli <TAB> # Command completion mycli command --<TAB> # Flag completion Every time you enter <TAB>, the autocomplete feature displays a list of commands (or flags if you type --), along with their summaries. Enter a letter and then <TAB> again to narrow down the list until you end up with the complete command that you want to execute. Enjoy!
Expected behavior
PowerShell 7 (pwsh) should be detected correctly regardless of admin privileges.
Environment (please complete the following information):
- OS: Windows 11
- PowerShell version: 7.5.4
- oclif/core version: 4.8.0
Additional context
PowerShell 7's own $ShellId variable correctly returns Microsoft.PowerShell, confirming it's a PowerShell environment. However, oclif's detection relies on process.title as seen by Node.js, which shows "pwsh" instead of something containing "powershell" when not running as admin. This means oclif's detection method is fundamentally misaligned with how PowerShell 7 identifies itself in non-admin mode.