JanDeDobbeleer / oh-my-posh

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

Cannot handle mutated vowels in profile paths #2922

Closed crazycrank closed 2 years ago

crazycrank commented 2 years ago

Code of Conduct

What happened?

When trying to apply a custom theme which is located in a directory using special chars, in my case mutated vowels like äöü (but i guess other chars as well), the profile does not get applied.

  1. Create a custom theme
  2. Move it to a directory with a mutated vowel, e.g. D:\testü
  3. Configure oh-my-posh oh-my-posh init pwsh --config D:\testü\custom.omp.json | Invoke-Expression

--> Nothing happens

  1. Change the path to D:\testu
  2. Configure oh-my-posh oh-my-posh init pwsh --config D:\testu\custom.omp.json | Invoke-Expression

--> The theme gets applied

Theme

{ "blocks": [ { "alignment": "left", "type": "prompt", "segments": [ { "background": "#ffe9aa", "foreground": "#100e23", "powerline_symbol": "\ue0b0", "style": "powerline", "template": " \uf0e7 ", "type": "root" }, { "background": "#ffffff", "foreground": "#100e23", "powerline_symbol": "\ue0b0", "style": "powerline", "type": "time" }, { "background": "#91ddff", "foreground": "#100e23", "powerline_symbol": "\ue0b0", "properties": { "folder_icon": "\uf115", "folder_separator_icon": " \ue0b1 ", "style": "full" }, "style": "powerline", "template": " {{ .Path }} ", "type": "path" }, { "type": "git", "style": "powerline", "powerline_symbol": "\uE0B0", "foreground": "#193549", "background": "#95ffa4", "background_templates": [ "{{ if or (.Working.Changed) (.Staging.Changed) }}#fff38c{{ end }}", "{{ if and (gt .Ahead 0) (gt .Behind 0) }}#ff645e{{ end }}", "{{ if gt .Ahead 0 }}#b388ff{{ end }}", "{{ if gt .Behind 0 }}#f5a15d{{ end }}" ], "template": " {{ .UpstreamIcon }}{{ .HEAD }}{{if .BranchStatus }} {{ .BranchStatus }}{{ end }}{{ if .Working.Changed }} \uF044 {{ .Working.String }}{{ end }}{{ if and (.Working.Changed) (.Staging.Changed) }} |{{ end }}{{ if .Staging.Changed }} \uF046 {{ .Staging.String }}{{ end }}{{ if gt .StashCount 0 }} \uF692 {{ .StashCount }}{{ end }}", "properties": { "fetch_status": true, "fetch_stash_count": true, "fetch_upstream_icon": true, "untracked_modes": { "/Users/user/Projects/oh-my-posh/": "no" } } }, { "background": "#906cff", "foreground": "#100e23", "powerline_symbol": "\ue0b0", "style": "powerline", "template": " \ue235 {{ if .Error }}{{ .Error }}{{ else }}{{ if .Venv }}{{ .Venv }} {{ end }}{{ .Full }}{{ end }} ", "type": "python" }, { "background": "#ff8080", "foreground": "#ffffff", "powerline_symbol": "\ue0b0", "style": "powerline", "template": " \ue20f ", "type": "exit" } ] }, { "alignment": "left", "type": "prompt", "newline": true, "segments": [ { "foreground": "#007ACC", "style": "plain", "template": "\u276f ", "type": "text" } ] } ], "version": 2 }

What OS are you seeing the problem on?

Windows

Which shell are you using?

powershell

Log output

sorry too much private information
JanDeDobbeleer commented 2 years ago

@crazycrank that's because PowerShell and UTF-8 is real pain. To fix that, please init oh-my-posh in UTF-8, we have to do the same in other places ourselves as well. One day they will fix this....

$previousOutputEncoding = [Console]::OutputEncoding
try {
    [Console]::OutputEncoding = [Text.Encoding]::UTF8
    oh-my-posh init pwsh --config D:\testü\custom.omp.json | Invoke-Expression
} finally {
    [Console]::OutputEncoding = $previousOutputEncoding
}
crazycrank commented 2 years ago

This worked, thanks a lot.

A more general question, since you sound like you have some experience on the topic. Is there a reason to not keep the encoding at UTF-8?

JanDeDobbeleer commented 2 years ago

@crazycrank yes, as PowerShell isn't yet fully UTF8, the functionalities of certain CLI tools isn't guaranteed. But mostly, it doesn't impact much looking at EU systems. Asian locale's however usually break.

akulbe commented 1 year ago

Hey Jan - I tried this, I'm not sure if I have the syntax right or not. See the two screenshots.

image

image

JanDeDobbeleer commented 1 year ago

@akulbe 9/10 it's the backslashes being interpreted as escape sequences. Try replacing those with forward slashes.

akulbe commented 1 year ago

No dice. I switched from \ to /file-wide. Same result.

akulbe commented 1 year ago

If this helps… https://gist.github.com/akulbe/ec5565557c263f82eefce6c6eb6e328b it's my $PROFILE

JanDeDobbeleer commented 1 year ago

@akulbe what's the output of oh-my-posh.exe init pwsh --config "C:/Users/Aaron Kulbe/AppData/Local/Programs/oh-my-posh/themes/powerline.omp.json"?

akulbe commented 1 year ago
image
JanDeDobbeleer commented 1 year ago

@akulbe you seem to have a really old version of oh-my-posh installed. Can you validate that there's no duplicate old installation somewhere? Because that output has been removed a long time ago (and would explain the issue as well). Did you perhaps migrate from the module?

akulbe commented 1 year ago

That must have been it. I used Revo Uninstaller Pro to scan, and there was some leftover cruft. Reinstalled from winget, and now it's working as expected.

image

Thank you both for your time, and your help!!

github-actions[bot] commented 9 months ago

This issue has been automatically locked since there has not been any recent activity (i.e. last half year) after it was closed. It helps our maintainers focus on the active issues. If you have found a problem that seems similar, please open a discussion first, complete the body with all the details necessary to reproduce, and mention this issue as reference.