Skip to content

Commit fbf9b88

Browse files
committed
docs(clap_complete): fix instructions to source PowerShell completions
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 cb49eba commit fbf9b88

File tree

1 file changed

+25
-22
lines changed

1 file changed

+25
-22
lines changed

clap_complete/src/env/mod.rs

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -35,32 +35,35 @@
3535
//!
3636
//! </div>
3737
//!
38-
//! Bash
39-
//! ```bash
40-
//! echo "source <(COMPLETE=bash your_program)" >> ~/.bashrc
41-
//! ```
38+
//! - **Bash**
39+
//! ```bash
40+
//! echo "source <(COMPLETE=bash your_program)" >> ~/.bashrc
41+
//! ```
4242
//!
43-
//! Elvish
44-
//! ```elvish
45-
//! echo "eval (E:COMPLETE=elvish your_program | slurp)" >> ~/.elvish/rc.elv
46-
//! ```
43+
//! - **Elvish**
44+
//! ```elvish
45+
//! echo "eval (E:COMPLETE=elvish your_program | slurp)" >> ~/.elvish/rc.elv
46+
//! ```
4747
//!
48-
//! Fish
49-
//! ```fish
50-
//! echo "COMPLETE=fish your_program | source" >> ~/.config/fish/config.fish
51-
//! ```
48+
//! - **Fish**
49+
//! ```fish
50+
//! echo "COMPLETE=fish your_program | source" >> ~/.config/fish/config.fish
51+
//! ```
5252
//!
53-
//! Powershell
54-
//! ```powershell
55-
//! $env:COMPLETE = "powershell"
56-
//! echo "your_program | Out-String | Invoke-Expression" >> $PROFILE
57-
//! Remove-Item Env:\COMPLETE
58-
//! ```
53+
//! - **Powershell**
54+
//! ```powershell
55+
//! echo '$env:COMPLETE = "powershell"; your_program | Out-String | Invoke-Expression; Remove-Item Env:\COMPLETE' >> $PROFILE
56+
//! ```
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.
5959
//!
60-
//! Zsh
61-
//! ```zsh
62-
//! echo "source <(COMPLETE=zsh your_program)" >> ~/.zshrc
63-
//! ```
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
62+
//!
63+
//! - **Zsh**
64+
//! ```zsh
65+
//! echo "source <(COMPLETE=zsh your_program)" >> ~/.zshrc
66+
//! ```
6467
//!
6568
//! To disable completions, you can set `COMPLETE=` or `COMPLETE=0`
6669

0 commit comments

Comments
 (0)