JanDeDobbeleer / oh-my-posh

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

Fail to `toggle <type>` because of inconsistent PIDs when caching #3096

Closed YDX-2147483647 closed 1 year ago

YDX-2147483647 commented 1 year ago

Code of Conduct

What happened?

Background

v12.15.0 introduces oh-my-posh toggle <type> to hide or show a segment in a shell session.

As explained in #3086 , the toggles are stored in the per-session cache, whose name contains the PID.

https://github.com/JanDeDobbeleer/oh-my-posh/blob/63bb1b4729e7aae0218101b46183bdd51084c928/src/platform/shell.go#L42

Issue

However, sometimes the PID of oh-my-posh toggle <type>, oh-my-posh get toggles and the prompt can be different

↓ I toggle <something> in PID x, but get toggles in PID y, and the prompt may render in PID z. (Windows, PowerShell 7, slim)

(main) > oh-my-posh toggle git

(main) > oh-my-posh get toggles
No segments are toggled off

(main) > rg toggle (oh-my-posh cache path) -A 5  # rg ≈ grep
107:    "toggle_cache_21344": {
108-        "value": "git",
109-        "timestamp": 1668767288, // This matches 18:28:08, when I `toggle git`
110-        "ttl": -1
111-    }

on Windows

↓ In the codespace, I rebuild it with fmt.Println(platform.TOGGLECACHE) in src/cli/get.go, src/cli/toggle.go and src/engine/segment.go. (bash, default theme)

(main) $ oh-my-posh get toggles
toggle_cache_29787 (from get.go)
No segments are toggled off
validate toggles?  false toggle_cache_30026 (from segment.go)

(main) $ oh-my-posh toggle git
toggle_cache_29787 (from toggle.go)
validate toggles?  false toggle_cache_30121 (from segment.go)

(main) $

codespace codespace

Theme

It's not the theme/config.

I have checked several themes (default, slim, zash on Windows + PowerShell 7) and tried in the codespace (default theme, bash). All of them behaves similarly.

What OS are you seeing the problem on?

Windows

Which shell are you using?

powershell

Log output

Sorry I believe `oh-my-posh debug` won't help here.

I have tried `oh-my-posh debug` several times. I'm glab to paste it here if anyone asks.
JanDeDobbeleer commented 1 year ago

@YDX-2147483647 I'm certain this is a PowerShell only problem so I'll fix it there. I can't reproduce at all on macOS using any other shell.

YDX-2147483647 commented 1 year ago

Everything works fine now. Thanks!

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.