JanDeDobbeleer / oh-my-posh

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

Transient prompt prints path from another terminal window #5182

Closed IsaiahGrace closed 2 months ago

IsaiahGrace commented 2 months ago

Code of Conduct

What happened?

I'm using cmd + clink on Windows 11. I noticed that after switching terminal windows, the transient prompt will print the path of the previous window once before reverting to the correct value. It seems like the value used to print the path in the transient prompt is not updated at the correct time.

OMP bug

Theme

I'm using a slightly modified version of this theme: https://github.com/dreamsofautonomy/zen-omp/blob/main/zen.toml

#:schema https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json

version = 2
final_space = true
console_title_template = '{{ .Shell }} in {{ .Folder }}'

[[blocks]]
  type = 'prompt'
  alignment = 'left'
  # newline = true

  [[blocks.segments]]
    type = 'path'
    style = 'plain'
    background = 'transparent'
    foreground = 'blue'
    template = '{{ .Path }}'

    [blocks.segments.properties]
      style = 'full'

  [[blocks.segments]]
    type = 'git'
    style = 'plain'
    foreground = 'p:grey'
    background = 'transparent'
    template = ' {{ .HEAD }}{{ if or (.Working.Changed) (.Staging.Changed) }}*{{ end }} <cyan>{{ if gt .Behind 0 }}⇣{{ end }}{{ if gt .Ahead 0 }}⇡{{ end }}</>'

    [blocks.segments.properties]
      branch_icon = ''
      commit_icon = '@'
      fetch_status = true

[[blocks]]
  type = 'rprompt'
  overflow = 'hidden'

  [[blocks.segments]]
    type = 'executiontime'
    style = 'plain'
    foreground = 'yellow'
    background = 'transparent'
    template = '{{ .FormattedMs }}'

    [blocks.segments.properties]
      threshold = 5000

[[blocks]]
  type = 'prompt'
  alignment = 'left'
  newline = true

  [[blocks.segments]]
    type = 'text'
    style = 'plain'
    foreground_templates = [
      "{{if gt .Code 0}}red{{end}}",
      "{{if eq .Code 0}}magenta{{end}}",
    ]
    background = 'transparent'
    template = '❯'

[transient_prompt]
  foreground_templates = [
    "{{if gt .Code 0}}red{{end}}",
    "{{if eq .Code 0}}magenta{{end}}",
  ]
  background = 'transparent'
  template = '<blue>{{ .PWD }}</> ❯ '

[secondary_prompt]
  foreground = 'magenta'
  background = 'transparent'
  template = '❯❯ '

What OS are you seeing the problem on?

Windows

Which shell are you using?

cmd

Log output

~ ❯ oh-my-posh.exe debug --plain

Version: 21.16.2

Shell: cmd (clink v1.6.13.eb61b2)

Prompt:

~
❯

Segments:

ConsoleTitle(true)                        -   0 ms
Path(true)                                -   0 ms
Executiontime(false)                      -   0 ms
Text(true)                                -   0 ms

Run duration: 14.2537ms

Cache path: C:\Users\grace.isaiah\AppData\Local\oh-my-posh

Config path: C:\Users\grace.isaiah\Documents\projects\repos\notes\bin\clink\zen.toml

Logs:

[DEBUG] 11:40:35.500 shell.go:Getenv:326 → NO DATA
[TRACE] 11:40:35.500 shell.go:Getenv(TERM_PROGRAM) - 0s
[DEBUG] 11:40:35.500 shell.go:Getenv:326 → C:\Users\grace.isaiah\AppData\Local
[TRACE] 11:40:35.500 shell.go:Getenv(LOCALAPPDATA) - 0s
[TRACE] 11:40:35.500 shell_windows.go:CachePath() - 66µs
[DEBUG] 11:40:35.500 shell.go:Getenv:326 → C:\Users\grace.isaiah\Documents\projects\repos\notes\bin\clink\zen.toml
[TRACE] 11:40:35.500 shell.go:Getenv(POSH_THEME) - 0s
[DEBUG] 11:40:35.500 shell.go:Shell:601 → no shell name provided in flags, trying to detect it
[DEBUG] 11:40:35.504 shell.go:Shell:609 → process name: cmd.exe
[TRACE] 11:40:35.504 shell.go:Shell() - 3.8925ms
[TRACE] 11:40:35.504 shell.go:resolveConfigPath() - 3.8925ms
[TRACE] 11:40:35.504 shell.go:Init() - 4.4718ms
[TRACE] 11:40:35.504 shell.go:Flags() - 0s
[TRACE] 11:40:35.505 config.go:loadConfig() - 749.3µs
[TRACE] 11:40:35.505 shell.go:Flags() - 0s
[DEBUG] 11:40:35.505 shell.go:Getenv:326 → NO DATA
[TRACE] 11:40:35.505 shell.go:Getenv(OMP_CACHE_DISABLED) - 0s
[TRACE] 11:40:35.505 shell_windows.go:WindowsRegistryKeyValue(HKEY_CURRENT_USER\Software\Microsoft\Windows\DWM\ColorizationColor) - 0s
[TRACE] 11:40:35.505 shell.go:GOOS() - 0s
[TRACE] 11:40:35.505 shell.go:GOOS() - 0s
[TRACE] 11:40:35.505 shell.go:GOOS() - 0s
[TRACE] 11:40:35.505 shell.go:GOOS() - 0s
[TRACE] 11:40:35.505 shell.go:GOOS() - 0s
[TRACE] 11:40:35.505 shell.go:GOOS() - 0s
[TRACE] 11:40:35.505 shell.go:GOOS() - 0s
[TRACE] 11:40:35.505 shell.go:GOOS() - 0s
[TRACE] 11:40:35.505 shell.go:GOOS() - 0s
[TRACE] 11:40:35.505 shell.go:GOOS() - 0s
[TRACE] 11:40:35.505 shell.go:GOOS() - 0s
[TRACE] 11:40:35.505 shell.go:GOOS() - 0s
[TRACE] 11:40:35.505 shell.go:GOOS() - 0s
[TRACE] 11:40:35.505 shell.go:GOOS() - 0s
[TRACE] 11:40:35.505 shell.go:GOOS() - 0s
[TRACE] 11:40:35.505 shell.go:GOOS() - 0s
[TRACE] 11:40:35.505 shell.go:GOOS() - 0s
[TRACE] 11:40:35.505 shell.go:GOOS() - 0s
[TRACE] 11:40:35.505 shell.go:GOOS() - 0s
[DEBUG] 11:40:35.505 shell_windows.go:WindowsRegistryKeyValue:217 → ColorizationColor(DWORD): 0xC40078D4
[TRACE] 11:40:35.505 shell.go:Shell() - 0s
[DEBUG] 11:40:35.505 shell.go:Getenv:326 → clink v1.6.13.eb61b2
[TRACE] 11:40:35.505 shell.go:Getenv(POSH_SHELL_VERSION) - 0s
[DEBUG] 11:40:35.505 debug.go:PrintDebug:22 → Segment: Title
[DEBUG] 11:40:35.505 text.go:Render:72 → Rendering template: {{ .Shell }} in {{ .Folder }}
[TRACE] 11:40:35.505 shell_windows.go:Root() - 0s
[TRACE] 11:40:35.505 shell.go:Shell() - 0s
[TRACE] 11:40:35.505 shell.go:StatusCodes() - 0s
[TRACE] 11:40:35.505 shell_windows.go:IsWsl() - 0s
[DEBUG] 11:40:35.505 shell.go:TemplateCache:782 → environment: [=::=::\ =C:=C:\Users\grace.isaiah =clink.bin=C:\Program Files (x86)\clink =clink.id=10164 =clink.profile=C:\Users\grace.isaiah\AppData\Local\clink =clink.scripts= =cwdhistory_injected=1 =ExitCode=00000000 ALACRITTY_LOG=C:\Documents and Settings\grace.isaiah\Local Settings\Temp\Alacritty-13744.log ALLUSERSPROFILE=C:\ProgramData ANT_HOME=C:\ant-1.10.14 APPDATA=C:\Users\grace.isaiah\AppData\Roaming CLINK_DIR=C:\Program Files (x86)\clink clink_dummy_capture_env=  COLORTERM=truecolor COLUMNS=213 CommonProgramFiles=C:\Program Files\Common Files CommonProgramFiles(x86)=C:\Program Files (x86)\Common Files CommonProgramW6432=C:\Program Files\Common Files ComSpec=C:\windows\system32\cmd.exe DriverData=C:\Windows\System32\Drivers\DriverData EFC_5956=1 FPS_BROWSER_APP_PROFILE_STRING=Internet Explorer FPS_BROWSER_USER_PROFILE_STRING=Default HOME=C:\Users\grace.isaiah HOMEDRIVE=C: HOMEPATH=\Users\grace.isaiah LINES=53 LOCALAPPDATA=C:\Users\grace.isaiah\AppData\Local NUMBER_OF_PROCESSORS=16 OS=Windows_NT PAGER=less Path=C:\Program Files\Alacritty\;C:\windows\system32;C:\windows;C:\windows\System32\Wbem;C:\windows\System32\WindowsPowerShell\v1.0\;C:\windows\System32\OpenSSH\;C:\Program Files\dotnet\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files (x86)\doxygen\bin;C:\Program Files (x86)\Graphviz2.20\bin;C:\ant-1.10.14\bin;C:\Program Files\OpenSSL-Win64\bin;C:\Program Files\Java\jdk-17.0.2\bin;C:\Program Files\Git\cmd;C:\Program Files\Inkscape\bin;C:\Program Files\PuTTY\;C:\Python27;C:\Users\grace.isaiah\AppData\Local\Programs\Python\Launcher\;C:\Users\grace.isaiah\AppData\Local\Microsoft\WindowsApps;C:\GnuWin32\bin;C:\Users\grace.isaiah\AppData\Local\Programs\oh-my-posh\bin; PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC POSH_CURSOR_LINE=2 POSH_INSTALLER=manual POSH_PID=093c975e-db2d-b840-1522-f7100689992a POSH_SHELL_VERSION=clink v1.6.13.eb61b2 POSH_THEME=C:\Users\grace.isaiah\Documents\projects\repos\notes\bin\clink\zen.toml POSH_THEMES_PATH=C:\Users\grace.isaiah\AppData\Local\Programs\oh-my-posh\themes PROCESSOR_ARCHITECTURE=AMD64 PROCESSOR_IDENTIFIER=Intel64 Family 6 Model 186 Stepping 2, GenuineIntel PROCESSOR_LEVEL=6 PROCESSOR_REVISION=ba02 ProgramData=C:\ProgramData ProgramFiles=C:\Program Files ProgramFiles(x86)=C:\Program Files (x86) ProgramW6432=C:\Program Files PROMPT$P$G PSModulePath=C:\Program Files\WindowsPowerShell\Modules;C:\windows\system32\WindowsPowerShell\v1.0\Modules PUBLIC=C:\Users\Public SESSIONNAME=Console SystemDrive=C: SystemRoot=C:\windows TEMP=C:\Documents and Settings\grace.isaiah\Local Settings\Temp TERM=xterm-256color TMP=C:\Documents and Settings\grace.isaiah\Local Settings\Temp UATDATA=C:\windows\CCM\UATData\D9F8C395-CAB8-491d-B8AC-179A1FE1BE77 USERNAME=grace.isaiah USERPROFILE=C:\Users\grace.isaiah windir=C:\windows ZES_ENABLE_SYSMAN=1]
[TRACE] 11:40:35.505 shell.go:GOOS() - 0s
[DEBUG] 11:40:35.505 shell.go:Pwd:356 → C:\Users\grace.isaiah
[TRACE] 11:40:35.506 shell.go:Pwd() - 503.2µs
[DEBUG] 11:40:35.506 shell_windows.go:58 → C:\Users\grace.isaiah
[TRACE] 11:40:35.506 shell_windows.go:IsWsl() - 0s
[TRACE] 11:40:35.506 shell.go:GOOS() - 0s
[TRACE] 11:40:35.506 shell.go:GOOS() - 0s
[TRACE] 11:40:35.506 shell.go:GOOS() - 0s
[TRACE] 11:40:35.506 shell.go:GOOS() - 0s
[TRACE] 11:40:35.506 shell.go:GOOS() - 0s
[TRACE] 11:40:35.506 shell.go:GOOS() - 0s
[TRACE] 11:40:35.506 shell.go:GOOS() - 0s
[TRACE] 11:40:35.506 shell.go:GOOS() - 0s
[TRACE] 11:40:35.506 shell.go:GOOS() - 0s
[TRACE] 11:40:35.506 shell.go:GOOS() - 0s
[TRACE] 11:40:35.506 shell.go:GOOS() - 0s
[TRACE] 11:40:35.506 shell.go:GOOS() - 0s
[TRACE] 11:40:35.506 shell.go:GOOS() - 0s
[TRACE] 11:40:35.506 shell.go:GOOS() - 0s
[TRACE] 11:40:35.506 shell.go:GOOS() - 0s
[DEBUG] 11:40:35.506 shell.go:User:494 → grace.isaiah
[TRACE] 11:40:35.506 shell.go:User() - 0s
[DEBUG] 11:40:35.506 shell.go:Host:511 → M3D91KS3
[TRACE] 11:40:35.506 shell.go:Host() - 0s
[TRACE] 11:40:35.506 shell.go:GOOS() - 0s
[DEBUG] 11:40:35.506 shell.go:Getenv:326 → NO DATA
[TRACE] 11:40:35.506 shell.go:Getenv(SHLVL) - 0s
[TRACE] 11:40:35.506 shell.go:TemplateCache() - 503.2µs
[DEBUG] 11:40:35.506 shell.go:Getenv:326 → 2
[TRACE] 11:40:35.506 shell.go:Getenv(POSH_CURSOR_LINE) - 0s
[DEBUG] 11:40:35.506 shell.go:Getenv:326 → NO DATA
[TRACE] 11:40:35.506 shell.go:Getenv(POSH_CURSOR_COLUMN) - 0s
[TRACE] 11:40:35.506 shell.go:Flags() - 0s
[TRACE] 11:40:35.506 shell.go:Flags() - 0s
[TRACE] 11:40:35.506 shell.go:Shell() - 0s
[TRACE] 11:40:35.506 shell.go:Shell() - 0s
[TRACE] 11:40:35.506 shell.go:Flags() - 0s
[TRACE] 11:40:35.506 shell.go:Flags() - 0s
[TRACE] 11:40:35.506 shell.go:Pwd() - 0s
[DEBUG] 11:40:35.506 shell_windows.go:58 → C:\Users\grace.isaiah
[TRACE] 11:40:35.506 shell.go:GOOS() - 0s
[DEBUG] 11:40:35.506 segment.go:SetEnabled:560 → Segment: Git
[TRACE] 11:40:35.506 shell.go:Pwd() - 0s
[TRACE] 11:40:35.506 shell.go:GOOS() - 0s
[DEBUG] 11:40:35.506 shell.go:Getenv:326 → C:\Users\grace.isaiah\AppData\Local
[DEBUG] 11:40:35.506 shell_windows.go:58 → C:\Users\grace.isaiah
[TRACE] 11:40:35.506 shell.go:Getenv(LOCALAPPDATA) - 0s
[TRACE] 11:40:35.506 shell.go:GOOS() - 0s
[DEBUG] 11:40:35.506 segment.go:SetEnabled:560 → Segment: Path
[DEBUG] 11:40:35.506 properties.go:GetBool:22 → display_cygpath: false
[TRACE] 11:40:35.506 shell.go:GOOS() - 0s
[TRACE] 11:40:35.506 shell.go:PathSeparator() - 0s
[TRACE] 11:40:35.506 shell.go:Pwd() - 0s
[TRACE] 11:40:35.506 shell.go:Shell() - 0s
[TRACE] 11:40:35.506 shell.go:Shell() - 0s
[DEBUG] 11:40:35.506 properties.go:GetBool:22 → mapped_locations_enabled: true
[DEBUG] 11:40:35.506 properties.go:GetString:28 → 
[DEBUG] 11:40:35.506 properties.go:GetString:28 → 
[DEBUG] 11:40:35.506 shell_windows.go:58 → C:\Users\grace.isaiah
[TRACE] 11:40:35.506 shell.go:GOOS() - 0s
[TRACE] 11:40:35.506 shell.go:GOOS() - 0s
[DEBUG] 11:40:35.506 properties.go:GetString:28 → ~
[DEBUG] 11:40:35.506 properties.go:GetKeyValueMap:46 → mapped_locations: map[]
[TRACE] 11:40:35.506 shell.go:GOOS() - 0s
[TRACE] 11:40:35.506 shell.go:GOOS() - 0s
[TRACE] 11:40:35.506 shell.go:GOOS() - 0s
[TRACE] 11:40:35.506 shell.go:GOOS() - 0s
[TRACE] 11:40:35.506 shell.go:GOOS() - 0s
[TRACE] 11:40:35.506 shell.go:GOOS() - 0s
[TRACE] 11:40:35.506 shell.go:GOOS() - 0s
[TRACE] 11:40:35.506 shell.go:GOOS() - 0s
[DEBUG] 11:40:35.506 properties.go:GetString:28 → NO DATA
[DEBUG] 11:40:35.506 shell_windows.go:58 → C:\Users\grace.isaiah
[TRACE] 11:40:35.506 shell.go:Pwd() - 0s
[TRACE] 11:40:35.506 shell.go:TemplateCache() - 0s
[TRACE] 11:40:35.506 shell.go:StackCount() - 0s
[DEBUG] 11:40:35.506 win32_windows.go:isWriteable:299 → not current user or in group
[DEBUG] 11:40:35.506 win32_windows.go:isWriteable:303 → current user is member of S-1-5-32-544
[DEBUG] 11:40:35.506 win32_windows.go:isWriteable:311 ↓
    WRITE_DAC
    WRITE_OWNER
    SYNCHRONIZE
    DELETE
    READ_CONTROL
[DEBUG] 11:40:35.506 win32_windows.go:isWriteable:313 → user has write access
[TRACE] 11:40:35.506 shell_windows.go:DirIsWritable() - 516.3µs
[TRACE] 11:40:35.506 shell.go:TemplateCache() - 0s
[DEBUG] 11:40:35.512 shell.go:CommandPath:553 → C:\Program Files\Git\cmd\git.exe
[TRACE] 11:40:35.512 shell.go:CommandPath(git.exe) - 6.441ms
[TRACE] 11:40:35.512 shell.go:HasCommand(git.exe) - 6.441ms
[TRACE] 11:40:35.512 shell.go:Pwd() - 0s
[ERROR] 11:40:35.512 shell.go:HasParentFilePath:697 → CreateFile .git: The system cannot find the file specified.
[TRACE] 11:40:35.512 shell.go:HasParentFilePath(.git) - 0s
[DEBUG] 11:40:35.512 properties.go:GetBool:22 → fetch_bare_info: false
[DEBUG] 11:40:35.512 text.go:Render:72 → Rendering template: {{ .Path }}
[TRACE] 11:40:35.513 shell.go:TemplateCache() - 0s
[DEBUG] 11:40:35.514 text.go:Render:72 → Rendering template: plain
[DEBUG] 11:40:35.514 text.go:Render:72 → Rendering template: plain
[TRACE] 11:40:35.514 shell.go:Shell() - 0s
[TRACE] 11:40:35.514 shell.go:Shell() - 0s
[TRACE] 11:40:35.514 shell.go:Shell() - 0s
[TRACE] 11:40:35.514 shell.go:Shell() - 0s
[TRACE] 11:40:35.514 shell.go:Shell() - 0s
[TRACE] 11:40:35.514 shell.go:Flags() - 0s
[TRACE] 11:40:35.514 shell.go:Pwd() - 0s
[DEBUG] 11:40:35.514 shell_windows.go:58 → C:\Users\grace.isaiah
[TRACE] 11:40:35.514 shell.go:GOOS() - 0s
[DEBUG] 11:40:35.514 segment.go:SetEnabled:560 → Segment: Text
[TRACE] 11:40:35.514 shell.go:TemplateCache() - 0s
[DEBUG] 11:40:35.514 text.go:Render:72 → Rendering template: ❯
[DEBUG] 11:40:35.514 shell.go:Getenv:326 → NO DATA
[TRACE] 11:40:35.514 shell.go:Getenv(TERM_PROGRAM) - 0s
[TRACE] 11:40:35.514 shell.go:Shell() - 0s
[DEBUG] 11:40:35.514 text.go:Render:72 → Rendering template: {{if gt .Code 0}}red{{end}}
[TRACE] 11:40:35.514 shell.go:TemplateCache() - 0s
[DEBUG] 11:40:35.514 text.go:Render:72 → Rendering template: {{if eq .Code 0}}magenta{{end}}
[TRACE] 11:40:35.514 shell.go:TemplateCache() - 0s
[DEBUG] 11:40:35.514 text.go:Render:72 → Rendering template: plain
[TRACE] 11:40:35.514 shell.go:Shell() - 0s
[TRACE] 11:40:35.514 shell.go:Shell() - 0s
[TRACE] 11:40:35.514 shell.go:Flags() - 0s
[TRACE] 11:40:35.514 shell.go:Shell() - 0s
[TRACE] 11:40:35.514 shell.go:Shell() - 0s
[DEBUG] 11:40:35.514 shell.go:Getenv:326 → C:\Users\grace.isaiah\AppData\Local
[TRACE] 11:40:35.514 shell.go:Getenv(LOCALAPPDATA) - 0s
[TRACE] 11:40:35.514 shell_windows.go:CachePath() - 0s
[TRACE] 11:40:35.514 shell.go:Flags() - 0s
JanDeDobbeleer commented 2 months ago

@IsaiahGrace I think this is because that an async process, but need to check. Maybe @chrisant996 knows what's going on here.

chrisant996 commented 2 months ago

@JanDeDobbeleer does oh-my-posh use a temp file to cache previous prompt state?

Maybe it's not qualifying the temp file name, and all windows are sharing the same temp file?

JanDeDobbeleer commented 2 months ago

@chrisant996 it's a session guid so that should "work", I can check though. Maybe on cmd that's not working as expected. It's a bit of a different animal 😅

chrisant996 commented 2 months ago

Where does the session guid come from? There's no such thing in Windows. There's a Windows Terminal session guid, but it's an environment variable and is probably about the terminal session, not the CMD session.

You probably need to use the CMD process ID instead.

JanDeDobbeleer commented 2 months ago

Where does the session guid come from?

@chrisant996 it's generated here. Should be unique, and that's also how we cache the prompt data and retrieve it with that key when generating the transient prompt.

chrisant996 commented 2 months ago

It's behaving like the temp file is "bleeding through" between CMD processes.

I can take a closer look sometime next week if it hasn't been figured out by then.

(Clink isn't doing it, btw. This is happening in the custom prompt script.)

JanDeDobbeleer commented 2 months ago

@chrisant996 check, I already figured out that the environment variable is shared across the shells. So that's the issue.

chrisant996 commented 2 months ago

Oh wait a minute. It's using math.random, so it's pseudo random. That's not really a guid.

Have you tested to make sure it isn't picking the same random number the first time each session tries to get a guid?

I think you need to at a minimum seed the pseudo random number generator with os.clock() * 10000 (ten thousand).

JanDeDobbeleer commented 2 months ago

@chrisant996 yup, it generates the same thing every time. You mentioned

You probably need to use the CMD process ID instead.

which might be the most straightforward solution.

IsaiahGrace commented 2 months ago

Thanks for the fix! I was going to just live with the strange behavior, but I'm glad I posted the bug! I upgraded to 21.17.1 and everything is looking good.

image

JanDeDobbeleer commented 2 months ago

@IsaiahGrace always post the bug 😄. And thanks @chrisant996 for being my rubber duck here 🙏🏻

JanDeDobbeleer commented 2 months ago

@holopin-bot @chrisant996 helping

holopin-bot[bot] commented 2 months ago

Congratulations @chrisant996, the maintainer of this repository has issued you a badge! Here it is: https://holopin.io/claim/clxz7ce6u29910cl6rtfladm7

This badge can only be claimed by you, so make sure that your GitHub account is linked to your Holopin account. You can manage those preferences here: https://holopin.io/account. Or if you're new to Holopin, you can simply sign up with GitHub, which will do the trick!