Skip to content

fix(shell): auto-configure PowerShell on Windows when SHELL is not set#898

Merged
max-sixty merged 6 commits intomainfrom
pwsh
Jan 29, 2026
Merged

fix(shell): auto-configure PowerShell on Windows when SHELL is not set#898
max-sixty merged 6 commits intomainfrom
pwsh

Conversation

@max-sixty
Copy link
Owner

Summary

  • Auto-detect Windows-native shells (cmd/PowerShell) by checking if SHELL env var is absent
  • When detected, create both PowerShell profile files (pwsh 7+ and Windows PowerShell 5.1)
  • Fix preview output to show "shell extension" instead of "& completions" for PowerShell

Fixes #885

Test plan

  • Unit tests pass
  • Integration test for WORKTRUNK_TEST_POWERSHELL_ENV override
  • Manual verification of --dry-run and ? preview output

🤖 Generated with Claude Code

max-sixty and others added 5 commits January 28, 2026 11:27
Introduce is_powershell_environment() function to detect PowerShell sessions via PSModulePath env var. Use this detection to auto-configure PowerShell when running `wt config shell install` from a PowerShell session, even if the profile doesn't exist yet (issue #885). On non-Windows, add PowerShell to the default shells list when detected. Rename explicit_shell parameter to allow_create for clarity, representing whether config files can be created for a shell.
On Windows, PSModulePath is set system-wide (even in Git Bash, cmd),
making it unreliable for detecting PowerShell sessions. This caused
false positives where `wt config shell install` would create PowerShell
profiles when run from Git Bash.

Changes:
- Restrict is_powershell_environment() to non-Windows only
- On Windows, require explicit `install powershell` to create profile
- Add Windows-specific hint when PowerShell is skipped
- Use var_os() instead of var() for robust env var checking

On macOS/Linux, PowerShell Core must be explicitly installed, so
PSModulePath being set is a reliable signal for auto-detection.

Co-Authored-By: Claude <noreply@anthropic.com>
On Windows, detect Windows-native shells (cmd/PowerShell) by checking
if the SHELL env var is NOT set. Git Bash, MSYS2, and Cygwin set SHELL,
but cmd.exe and PowerShell don't.

When detected, create both PowerShell profile files:
- Documents/PowerShell/Microsoft.PowerShell_profile.ps1 (pwsh 7+)
- Documents/WindowsPowerShell/Microsoft.PowerShell_profile.ps1 (5.1)

This solves issue #885 where PowerShell users couldn't auto-configure
shell integration because PSModulePath detection had false positives.

Co-Authored-By: Claude <noreply@anthropic.com>
…igure_powershell

The new name better reflects the function's purpose: it determines whether
to auto-configure PowerShell profiles, not whether we're "in" PowerShell.

Also adds an integration test for the WORKTRUNK_TEST_POWERSHELL_ENV override
that verifies PowerShell profile creation works correctly.

Co-Authored-By: Claude <noreply@anthropic.com>
… preview

The preview output for `--dry-run` and `?` help was incorrectly showing
"shell extension & completions" for PowerShell. Only Bash/Zsh have inline
completions; Fish has separate files and PowerShell has no tab completion.

This makes the preview consistent with the actual install output.

Co-Authored-By: Claude <noreply@anthropic.com>
On CI environments:
- Linux: PowerShell Core is installed, setting PSModulePath
- Windows: Removing SHELL triggers the "SHELL not set" detection

Both cause should_auto_configure_powershell() to return true in tests,
adding PowerShell to the shell list and triggering the config hint.

Fix by:
1. Removing PSModulePath to prevent Linux false positive
2. Setting WORKTRUNK_TEST_POWERSHELL_ENV=0 to disable detection entirely
3. Skip the PowerShell detection test on Windows (Documents folder can't
   be easily overridden in tests)

Tests that need PowerShell detection should set the env var to "1".

Co-Authored-By: Claude <noreply@anthropic.com>
@max-sixty max-sixty merged commit dc753d0 into main Jan 29, 2026
20 of 21 checks passed
@max-sixty max-sixty deleted the pwsh branch January 29, 2026 06:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PowerShell shell integration is not working

1 participant