Skip to content

Fix PowerShell completion instruction syntax#1568

Merged
j178 merged 2 commits intomasterfrom
copilot/fix-powershell-completion-error
Feb 5, 2026
Merged

Fix PowerShell completion instruction syntax#1568
j178 merged 2 commits intomasterfrom
copilot/fix-powershell-completion-error

Conversation

Copy link
Contributor

Copilot AI commented Feb 5, 2026

The PowerShell completion instruction used bash-style environment variable syntax (COMPLETE=powershell prek), which fails in PowerShell with CommandNotFoundException.

Changes

  • Updated docs/installation.md to use PowerShell-native syntax for setting environment variables

Before:

Add-Content -Path $PROFILE -Value '(COMPLETE=powershell prek) | Out-String | Invoke-Expression'

After:

Add-Content -Path $PROFILE -Value '$env:COMPLETE = "powershell"; prek | Out-String | Invoke-Expression; Remove-Item Env:\COMPLETE'

The fix sets $env:COMPLETE using PowerShell syntax, invokes prek to generate the completion script, and cleans up the temporary environment variable.

Original prompt

This section details on the original issue you should resolve

<issue_title>Powershell completion script results in CommandNotFoundException</issue_title>
<issue_description>### Summary

Following the instructions for enabling Powershell shell completions, I ran Add-Content -Path $PROFILE -Value '(COMPLETE=powershell prek) | Out-String | Invoke-Expression'. This did what I expected it to: it added a line to my $PROFILE, (COMPLETE=powershell prek) | Out-String | Invoke-Expression.

However, also as expected, that line results in this error when the profile loads (and, indeed, if one types that string at the prompt:

COMPLETE=powershell : The term 'COMPLETE=powershell' is not recognized as the name of a cmdlet, function, script file, or operable
program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At C:\Users\Patrick\OneDrive\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1:357 char:2
+ (COMPLETE=powershell prek) | Out-String | Invoke-Expression
+  ~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (COMPLETE=powershell:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

If the problem isn't apparent, perhaps someone can tell me what it's designed to do so I can help? As a user of both Powershell & unix shells, I wasn't able to figure out what the command is that we want Powershell to run after glancing at some of the other completion scripts.

Platform

Windows 10 x86_64

Version

prek 0.3.1 (bc142a2 2026-01-31)

.pre-commit-config.yaml

not relevant

Log file

2026-02-05T03:33:51.720707Z DEBUG prek: 0.3.1 (bc142a2 2026-01-31)
2026-02-05T03:33:51.720806Z DEBUG Args: ["c:\users\username \.local\bin\prek.exe"]
2026-02-05T03:33:51.803464Z TRACE get_root: close time.busy=82.6ms time.idle=5.10µs</issue_description>

<agent_instructions>Fix the powershell completion instruction in installation.md: the style of running command with specified env var COMPLETE=powershell prek is bash-style, it does not work in powershell. Use something like $env:COMPLETE = "powershell"; prek | Out-String | Invoke-Expression; Remove-Item Env:\COMPLETE
</agent_instructions>

Comments on the Issue (you are @copilot in this section)

@j178 Thanks for the report! That instruction isn’t correct. Could you try adding this to your $PROFILE?
$env:COMPLETE = "powershell"
prek | Out-String | Invoke-Expression
Remove-Item Env:COMPLETE'
```</body></comment_new>
</comments>

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI changed the title [WIP] Fix CommandNotFoundException in Powershell completion script Fix PowerShell completion instruction syntax Feb 5, 2026
Copilot AI requested a review from j178 February 5, 2026 04:09
@j178 j178 marked this pull request as ready for review February 5, 2026 04:10
Copilot AI review requested due to automatic review settings February 5, 2026 04:10
@j178 j178 merged commit 752959e into master Feb 5, 2026
21 checks passed
@j178 j178 deleted the copilot/fix-powershell-completion-error branch February 5, 2026 04:11
@j178 j178 added the documentation Improvements or additions to documentation label Feb 5, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes the PowerShell shell completion installation instruction which was using bash-style environment variable syntax that fails in PowerShell with a CommandNotFoundException.

Changes:

  • Updated the PowerShell completion instruction in docs/installation.md to use PowerShell-native syntax for setting environment variables

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Powershell completion script results in CommandNotFoundException

3 participants