Skip to content

Commit e495ab1

Browse files
committed
docs(complete): Fix sourcing completions for pwsh
The previous instructions were wrong in that they set the `COMPLETE` env var only while the `$PROFILE` script was written. This was akin to COMPLETE=bash echo "source <(your_program)" >> ~/.bashrc whereas the corrected version sets `COMPLETE` as part of the `$PROFILE` script, mirroring the instructions for sourcing completion in the other shells. Extending `$PROFILE` in this way also requires that scripts are allowed to be executed. This requires changing the execution policy from its default value `Restricted` on Windows. There's no such issue when using PowerShell on macOS or Linux.
1 parent 20938a8 commit e495ab1

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

clap_complete/src/env/mod.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,13 @@
5252
//!
5353
//! **Powershell**
5454
//! ```powershell
55-
//! $env:COMPLETE = "powershell"
56-
//! echo "your_program | Out-String | Invoke-Expression" >> $PROFILE
57-
//! Remove-Item Env:\COMPLETE
55+
//! echo '$env:COMPLETE = "powershell"; your_program | Out-String | Invoke-Expression; Remove-Item Env:\COMPLETE' >> $PROFILE
5856
//! ```
57+
//! Note that to execute scripts in PowerShell on Windows, including [`$PROFILE`][$Profile],
58+
//! the [execution policy][ExecutionPolicies] needs to be set to `RemoteSigned` at minimum.
59+
//!
60+
//! [$Profile]: https://learn.microsoft.com/en-us/powershell/scripting/learn/shell/creating-profiles
61+
//! [ExecutionPolicies]: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_execution_policies
5962
//!
6063
//! **Zsh**
6164
//! ```zsh

0 commit comments

Comments
 (0)