Skip to content

Commit b2f3b02

Browse files
crutkasCopilot
andcommitted
docs(pwsh): guard profile initialization
Keep synced profiles quiet when Oh My Posh is not installed and establish UTF-8 console input and output before loading the prompt integration. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 30a4d06b-a9a5-4176-b3f2-8c554e037e21
1 parent 5c893f5 commit b2f3b02

2 files changed

Lines changed: 16 additions & 12 deletions

File tree

website/docs/installation/prompt.mdx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -217,16 +217,18 @@ to only require remote scripts to be signed using `Set-ExecutionPolicy -Executio
217217
Add the following snippet as the last line to your PowerShell profile script:
218218

219219
```powershell
220-
oh-my-posh init pwsh | Invoke-Expression
220+
$(if (Get-Command 'oh-my-posh' -ErrorAction Ignore) {
221+
oh-my-posh init pwsh
222+
# Set output encoding to UTF-8
223+
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
224+
# Set input encoding to UTF-8 (for reading user input with non-ASCII chars)
225+
[Console]::InputEncoding = [System.Text.Encoding]::UTF8
226+
}) | Invoke-Expression
221227
```
222228

223229
:::tip Execution policy
224230
In case the execution policy disables executing unsigned scripts on your system, you can fallback to evaluating
225-
the script instead. Use the `--eval` flag to do so:
226-
227-
```powershell
228-
oh-my-posh init pwsh --eval | Invoke-Expression
229-
```
231+
the script instead. Add the `--eval` flag to the `oh-my-posh init pwsh` command above.
230232

231233
Be aware this will make initializing the shell slower.
232234
:::

website/static/skills/ohmyposh/shell/powershell.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,13 @@ notepad $PROFILE
1818
Add this as the **last line**:
1919

2020
```powershell
21-
oh-my-posh init pwsh | Invoke-Expression
21+
$(if (Get-Command 'oh-my-posh' -ErrorAction Ignore) {
22+
oh-my-posh init pwsh
23+
# Set output encoding to UTF-8
24+
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
25+
# Set input encoding to UTF-8 (for reading user input with non-ASCII chars)
26+
[Console]::InputEncoding = [System.Text.Encoding]::UTF8
27+
}) | Invoke-Expression
2228
```
2329

2430
Reload the profile:
@@ -35,11 +41,7 @@ Reload the profile:
3541
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope LocalMachine
3642
```
3743

38-
Or use the `--eval` flag (slightly slower startup):
39-
40-
```powershell
41-
oh-my-posh init pwsh --eval | Invoke-Expression
42-
```
44+
Or add the `--eval` flag to the `oh-my-posh init pwsh` command above (slightly slower startup).
4345

4446
## Next step
4547

0 commit comments

Comments
 (0)