docs(faq): update about PowerShell UTF-8

This commit is contained in:
Y.D.X 2022-11-21 22:52:36 +08:00 committed by GitHub
parent a5aad7b058
commit 67d9a2589e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -177,8 +177,31 @@ For example:
Check the spelling of the name, or if a path was included, verify that the path is correct and try again. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
``` ```
The issue is that PowerShell on Windows doesn't yet default to UTF8. Resolve the issue by adding the following line The issue is that PowerShell on Windows doesn't yet default to UTF-8. Resolve the issue by setting the shell to UTF-8 in the scope of initializing Oh My Posh.
to the top of your `$PROFILE`:
:::info Why it matters?
If the location contains non-ASCII characters, non-UTF-8 PowerShell may provide a wrong path to Oh My Posh, which can break the initialization.
The scenario for non-ASCII location:
- Your computer has a non-ASCII user name.
- Your [config file](./installation/customize.mdx) is under your `$HOME`.
:::
To do so, edit your `$PROFILE`, find the line that initializes Oh My Posh (as highlighted below), and change it to the following:
```powershell
$previousOutputEncoding = [Console]::OutputEncoding
[Console]::OutputEncoding = [Text.Encoding]::UTF8
try {
// highlight-start
oh-my-posh init pwsh --config ~/custom.omp.json | Invoke-Expression
// highlight-end
} finally {
[Console]::OutputEncoding = $previousOutputEncoding
}
```
Alternatively, let the whole shell become UTF-8. (Be aware: Unwanted side effects can happen.) Add the following line to the top of your `$PROFILE`:
```powershell ```powershell
$OutputEncoding = [console]::InputEncoding = [console]::OutputEncoding = New-Object System.Text.UTF8Encoding $OutputEncoding = [console]::InputEncoding = [console]::OutputEncoding = New-Object System.Text.UTF8Encoding