JanDeDobbeleer / oh-my-posh

The most customisable and low-latency cross platform/shell prompt renderer
https://ohmyposh.dev
MIT License
16.83k stars 2.36k forks source link

Windows PowerShell works, pwsh 7.4.5 doesn't #5662

Closed underlines closed 2 hours ago

underlines commented 2 hours ago

Code of Conduct

What happened?

First of all: OMP is awesome and I use it for years. Love your work. I use it without problems in Windows Terminal + Windows PowerShell (the legacy one). But recently I had to move to MS pwsh (the open source one) and noticed it doesn't work (it never did on my machine, even on older versions).

System

Windows PowerShell

image

$PROFILE content:

oh-my-posh init pwsh --config ~/jandedobbeleer.omp.json | Invoke-Expression

Write-Host $error empty

debug

oh-my-posh debug pwsh

visual:

image

MS pwsh 7.4.5:

image

$PROFILE content:

oh-my-posh init pwsh --config ~/jandedobbeleer.omp.json | Invoke-Expression

Write-Host $error empty

debug

oh-my-posh debug pwsh

visual:

image

Theme

default: jandedobbeleer.omp.json

What OS are you seeing the problem on?

Windows

Which shell are you using?

powershell

Log output

[pwsh debug.txt](https://github.com/user-attachments/files/17118429/pwsh.debug.txt)
[Windows PowerShell debug.txt](https://github.com/user-attachments/files/17118426/Windows.PowerShell.debug.txt)
underlines commented 2 hours ago

Found your issue in PowerShell/PowerShell

[Console]::OutputEncoding = [Text.Encoding]::UTF8 fixed it, when added to $PROFILE before the OMP invokation.

So my init script now looks like this:

[Console]::OutputEncoding = [Text.Encoding]::UTF8
oh-my-posh init pwsh --config ~/jandedobbeleer.omp.json | Invoke-Expression
Import-Module -Name Terminal-Icons

If you compare both outputs exactly in my log output it really seems to be an encoding problem as you noted:

JanDeDobbeleer commented 2 hours ago

@underlines this is a PowerShell UTF8 issue they currently still refuse to fix. We can't solve that. You'll need to force the shell to UTF8 before initializing oh-my-posh.