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

Terminal not executing commands entered before prompt is printed #4072

Closed SFM61319 closed 1 year ago

SFM61319 commented 1 year ago

Code of Conduct

What happened?

The terminal is not executing commands entered before the prompt is printed when Oh My Posh is used. When not using Oh My Posh, the terminal executes commands entered before a prompt is printed, producing expected behavior.

Actual behavior image image
Expected behavior image image

Theme

Custom theme:

JSON ```json { "$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json", "version": 2, "final_space": true, "terminal_background": "transparent", "blocks": [ { "type": "prompt", "alignment": "left", "segments": [ { "type": "os", "style": "diamond", "foreground": "p:white", "background": "p:black", "leading_diamond": "", "trailing_diamond": "", "properties": { "ubuntu": " ", "windows": " " } }, { "type": "shell", "style": "diamond", "foreground": "p:white", "background": "p:black", "leading_diamond": "", "trailing_diamond": "" }, { "type": "sysinfo", "style": "diamond", "foreground": "p:white", "background": "p:black", "leading_diamond": "", "trailing_diamond": "", "template": " CPU: {{ round .PhysicalPercentUsed .Precision }}% | RAM: {{ (div ((sub .PhysicalTotalMemory .PhysicalFreeMemory)|float64) 1000000000.0) }}/{{ (div .PhysicalTotalMemory 1000000000.0) }}GB  " } ], "newline": true }, { "type": "prompt", "alignment": "right", "segments": [ { "type": "executiontime", "style": "diamond", "foreground": "p:white", "background": "p:black", "leading_diamond": "", "trailing_diamond": "", "template": " {{ .FormattedMs }}  ", "properties": { "style": "houston", "threshold": 0 } }, { "type": "time", "style": "diamond", "foreground": "p:white", "background": "p:black", "leading_diamond": "", "trailing_diamond": "", "properties": { "time_format": " Monday, 2006-01-02 15:04:05.000  " } } ] }, { "type": "prompt", "alignment": "left", "segments": [ { "type": "session", "style": "diamond", "foreground": "p:theme", "background": "p:black", "leading_diamond": "", "trailing_diamond": "" }, { "type": "path", "style": "diamond", "foreground": "p:black", "background": "p:theme", "leading_diamond": "", "trailing_diamond": "", "properties": { "style": "full" } } ], "newline": true }, { "type": "prompt", "alignment": "right", "segments": [ { "type": "git", "style": "diamond", "foreground": "p:black", "background": "p:green", "leading_diamond": "", "trailing_diamond": "", "template": " {{ .UpstreamIcon }}{{ .HEAD }}{{if .BranchStatus }} {{ .BranchStatus }}{{ end }}{{ if .Working.Changed }}  {{ .Working.String }}{{ end }}{{ if and (.Working.Changed) (.Staging.Changed) }} |{{ end }}{{ if .Staging.Changed }}  {{ .Staging.String }}{{ end }}{{ if gt .StashCount 0 }}  {{ .StashCount }}{{ end }} ", "properties": { "branch_icon": " ", "fetch_stash_count": true, "fetch_status": true, "fetch_upstream_icon": true, "fetch_worktree_count": true } } ] }, { "type": "prompt", "alignment": "left", "segments": [ { "type": "text", "style": "plain", "template": "$" } ], "newline": true } ], "palettes": { "template": "{{ if .WSL }}ubuntu{{ else }}windows{{ end }}", "list": { "windows": { "black": "#000000", "blue": "#4CC2FF", "green": "#1DB954", "orange": "#F39456", "white": "#FFFFFF", "theme": "p:blue" }, "ubuntu": { "black": "#000000", "blue": "#4CC2FF", "green": "#1DB954", "orange": "#F39456", "white": "#FFFFFF", "theme": "p:orange" } } } } ```

What OS are you seeing the problem on?

Windows, Linux

Which shell are you using?

bash

Log output

Logs ```Shell Version: 17.5.2 Shell: bash (5.1.16(1)-release) Segments: ConsoleTitle(false) - 0 ms - os(true) - 0 ms -  WSL at  shell(true) - 0 ms -  bash sysinfo(true) - 0 ms -  CPU: 34.84% | RAM: 4/8GB  executiontime(true) - 1 ms -  00:00:00.0  time(true) - 0 ms -   Thursday, 2023-07-20 02:49:53.329  session(true) - 0 ms -  sfm61319@Spidey path(true) - 0 ms -  ~ git(false) - 0 ms - text(true) - 0 ms - $ Run duration: 12.512528ms Cache path: /home/sfm61319/.cache/oh-my-posh Config path: /mnt/c/Users/Svass/AppData/Local/Programs/oh-my-posh/themes/sigma.omp.json Logs: [DEBUG] 02:49:53.319 shell.go:Getenv:398 → NO DATA [TRACE] 02:49:53.319 shell.go:Getenv(TERM_PROGRAM) - 17.202µs [DEBUG] 02:49:53.319 shell.go:Getenv:398 → NO DATA [TRACE] 02:49:53.319 shell.go:Getenv(XDG_CACHE_HOME) - 2.385µs [TRACE] 02:49:53.319 shell_unix.go:CachePath() - 12.414µs [DEBUG] 02:49:53.319 shell.go:Getenv:398 → /mnt/c/Users/Svass/AppData/Local/Programs/oh-my-posh/themes/sigma.omp.json [TRACE] 02:49:53.319 shell.go:Getenv(POSH_THEME) - 4.258µs [DEBUG] 02:49:53.319 shell_unix.go:Platform:71 → ubuntu [TRACE] 02:49:53.319 shell.go:resolveConfigPath() - 13.215µs [TRACE] 02:49:53.319 shell.go:Init() - 178.198µs [TRACE] 02:49:53.319 shell.go:Flags() - 40ns [TRACE] 02:49:53.325 config.go:loadConfig() - 6.625691ms [TRACE] 02:49:53.325 shell.go:Flags() - 120ns [DEBUG] 02:49:53.325 shell.go:Getenv:398 → NO DATA [TRACE] 02:49:53.325 shell.go:Getenv(OMP_CACHE_DISABLED) - 5.14µs [TRACE] 02:49:53.326 shell_unix.go:Root() - 672ns [DEBUG] 02:49:53.326 shell.go:Shell:645 → process name: bash [TRACE] 02:49:53.326 shell.go:Shell() - 465.925µs [TRACE] 02:49:53.326 shell.go:ErrorCode() - 100ns [DEBUG] 02:49:53.326 shell_unix.go:IsWsl:35 → true [TRACE] 02:49:53.326 shell_unix.go:IsWsl() - 3.657µs [TRACE] 02:49:53.326 shell.go:GOOS() - 60ns [DEBUG] 02:49:53.326 shell.go:Pwd:428 → /home/sfm61319 [TRACE] 02:49:53.326 shell.go:Pwd() - 10.249µs [TRACE] 02:49:53.326 shell.go:GOOS() - 30ns [TRACE] 02:49:53.326 shell.go:GOOS() - 20ns [TRACE] 02:49:53.326 shell.go:GOOS() - 30ns [TRACE] 02:49:53.326 shell.go:GOOS() - 20ns [TRACE] 02:49:53.326 shell.go:GOOS() - 20ns [TRACE] 02:49:53.326 shell.go:GOOS() - 30ns [TRACE] 02:49:53.326 shell.go:GOOS() - 20ns [TRACE] 02:49:53.326 shell.go:GOOS() - 21ns [TRACE] 02:49:53.326 shell.go:GOOS() - 30ns [TRACE] 02:49:53.326 shell.go:GOOS() - 50ns [DEBUG] 02:49:53.326 shell.go:User:549 → sfm61319 [TRACE] 02:49:53.326 shell.go:User() - 6.883µs [DEBUG] 02:49:53.326 shell.go:Host:561 → Spidey [TRACE] 02:49:53.326 shell.go:Host() - 3.346µs [TRACE] 02:49:53.326 shell.go:GOOS() - 30ns [DEBUG] 02:49:53.326 shell_unix.go:Platform:71 → ubuntu [DEBUG] 02:49:53.326 shell.go:Getenv:398 → 1 [TRACE] 02:49:53.326 shell.go:Getenv(SHLVL) - 2.084µs [TRACE] 02:49:53.326 shell.go:TemplateCache() - 553.641µs [TRACE] 02:49:53.326 shell.go:Shell() - 60ns [DEBUG] 02:49:53.326 shell.go:Getenv:398 → 5.1.16(1)-release [TRACE] 02:49:53.326 shell.go:Getenv(POSH_SHELL_VERSION) - 2.444µs [DEBUG] 02:49:53.326 debug.go:PrintDebug:23 → Segment: Title [TRACE] 02:49:53.326 shell.go:Flags() - 30ns [DEBUG] 02:49:53.326 block.go:Debug:280 → Segment: os [TRACE] 02:49:53.326 shell.go:Pwd() - 60ns [TRACE] 02:49:53.326 shell.go:GOOS() - 30ns [TRACE] 02:49:53.326 shell.go:GOOS() - 30ns [DEBUG] 02:49:53.326 shell_unix.go:Platform:71 → ubuntu [DEBUG] 02:49:53.326 properties.go:GetBool:22 → display_distro_name: false [DEBUG] 02:49:53.326 properties.go:GetString:28 →  [TRACE] 02:49:53.326 shell.go:TemplateCache() - 100ns [TRACE] 02:49:53.326 shell.go:TemplateCache() - 211ns [TRACE] 02:49:53.326 shell.go:Shell() - 151ns [DEBUG] 02:49:53.327 block.go:Debug:280 → Segment: shell [TRACE] 02:49:53.327 shell.go:Pwd() - 110ns [TRACE] 02:49:53.327 shell.go:GOOS() - 40ns [DEBUG] 02:49:53.327 properties.go:GetKeyValueMap:46 → mapped_shell_names: map[] [TRACE] 02:49:53.327 shell.go:Shell() - 40ns [TRACE] 02:49:53.327 shell.go:Flags() - 30ns [TRACE] 02:49:53.327 shell.go:TemplateCache() - 100ns [TRACE] 02:49:53.327 shell.go:TemplateCache() - 80ns [TRACE] 02:49:53.327 shell.go:Shell() - 50ns [DEBUG] 02:49:53.327 block.go:Debug:280 → Segment: sysinfo [DEBUG] 02:49:53.327 properties.go:GetInt:40 → precision: 2 [TRACE] 02:49:53.327 shell.go:Pwd() - 100ns [TRACE] 02:49:53.327 shell.go:GOOS() - 31ns [TRACE] 02:49:53.327 shell.go:TemplateCache() - 50ns [TRACE] 02:49:53.327 shell.go:TemplateCache() - 70ns [TRACE] 02:49:53.327 shell.go:Shell() - 100ns [TRACE] 02:49:53.327 shell.go:Flags() - 30ns [DEBUG] 02:49:53.327 block.go:Debug:280 → Segment: executiontime [TRACE] 02:49:53.327 shell.go:Pwd() - 70ns [TRACE] 02:49:53.327 shell.go:GOOS() - 30ns [DEBUG] 02:49:53.327 properties.go:GetBool:22 → always_enabled: false [TRACE] 02:49:53.327 shell.go:ExecutionTime() - 40ns [DEBUG] 02:49:53.327 properties.go:GetFloat64:34 → threshold: 0.000000 [DEBUG] 02:49:53.327 properties.go:GetString:28 → houston [TRACE] 02:49:53.327 shell.go:TemplateCache() - 120ns [TRACE] 02:49:53.329 shell.go:TemplateCache() - 321ns [TRACE] 02:49:53.329 shell.go:Shell() - 100ns [DEBUG] 02:49:53.329 block.go:Debug:280 → Segment: time [TRACE] 02:49:53.329 shell.go:Pwd() - 80ns [TRACE] 02:49:53.329 shell.go:GOOS() - 30ns [DEBUG] 02:49:53.329 properties.go:GetString:28 →  Monday, 2006-01-02 15:04:05.000  [TRACE] 02:49:53.329 shell.go:TemplateCache() - 100ns [TRACE] 02:49:53.329 shell.go:TemplateCache() - 81ns [TRACE] 02:49:53.329 shell.go:Shell() - 50ns [TRACE] 02:49:53.329 shell.go:Flags() - 30ns [DEBUG] 02:49:53.329 block.go:Debug:280 → Segment: session [TRACE] 02:49:53.329 shell.go:Pwd() - 40ns [TRACE] 02:49:53.329 shell.go:GOOS() - 40ns [DEBUG] 02:49:53.329 shell.go:Getenv:398 → NO DATA [TRACE] 02:49:53.329 shell.go:Getenv(SSH_CONNECTION) - 2.355µs [DEBUG] 02:49:53.329 shell.go:Getenv:398 → NO DATA [TRACE] 02:49:53.329 shell.go:Getenv(SSH_CLIENT) - 1.403µs [TRACE] 02:49:53.329 shell.go:TemplateCache() - 60ns [TRACE] 02:49:53.329 shell.go:TemplateCache() - 90ns [TRACE] 02:49:53.329 shell.go:Shell() - 60ns [DEBUG] 02:49:53.329 block.go:Debug:280 → Segment: path [TRACE] 02:49:53.329 shell.go:Pwd() - 30ns [TRACE] 02:49:53.329 shell.go:GOOS() - 30ns [TRACE] 02:49:53.329 shell.go:Pwd() - 30ns [TRACE] 02:49:53.329 shell.go:Shell() - 20ns [TRACE] 02:49:53.329 shell.go:Shell() - 20ns [DEBUG] 02:49:53.329 properties.go:GetBool:22 → mapped_locations_enabled: true [DEBUG] 02:49:53.329 properties.go:GetString:28 →  [DEBUG] 02:49:53.329 properties.go:GetString:28 →  [TRACE] 02:49:53.329 shell.go:GOOS() - 20ns [DEBUG] 02:49:53.329 properties.go:GetString:28 → ~ [DEBUG] 02:49:53.329 properties.go:GetKeyValueMap:46 → mapped_locations: map[] [TRACE] 02:49:53.329 shell.go:PathSeparator() - 40ns [TRACE] 02:49:53.329 shell.go:GOOS() - 30ns [TRACE] 02:49:53.329 shell.go:GOOS() - 30ns [TRACE] 02:49:53.329 shell.go:GOOS() - 30ns [TRACE] 02:49:53.329 shell.go:GOOS() - 30ns [TRACE] 02:49:53.329 shell.go:PathSeparator() - 20ns [TRACE] 02:49:53.329 shell.go:PathSeparator() - 70ns [TRACE] 02:49:53.329 shell.go:GOOS() - 30ns [TRACE] 02:49:53.329 shell.go:GOOS() - 20ns [TRACE] 02:49:53.329 shell.go:PathSeparator() - 30ns [TRACE] 02:49:53.329 shell.go:GOOS() - 20ns [TRACE] 02:49:53.329 shell.go:GOOS() - 30ns [TRACE] 02:49:53.329 shell.go:PathSeparator() - 30ns [TRACE] 02:49:53.329 shell.go:GOOS() - 20ns [TRACE] 02:49:53.329 shell.go:GOOS() - 20ns [TRACE] 02:49:53.329 shell.go:PathSeparator() - 20ns [TRACE] 02:49:53.330 shell.go:Pwd() - 30ns [DEBUG] 02:49:53.330 shell_unix.go:IsWsl:35 → true [TRACE] 02:49:53.330 shell_unix.go:IsWsl() - 2.635µs [DEBUG] 02:49:53.330 shell.go:RunCommand:579 → //wsl.localhost/Ubuntu/home/sfm61319 [TRACE] 02:49:53.330 shell.go:RunCommand(wslpath -m /home/sfm61319) - 663.79µs [TRACE] 02:49:53.330 shell.go:StackCount() - 80ns [TRACE] 02:49:53.330 shell_unix.go:DirIsWritable(/home/sfm61319) - 4.158µs [TRACE] 02:49:53.330 shell.go:TemplateCache() - 171ns [TRACE] 02:49:53.330 shell.go:TemplateCache() - 181ns [TRACE] 02:49:53.330 shell.go:Shell() - 90ns [TRACE] 02:49:53.330 shell.go:Flags() - 30ns [DEBUG] 02:49:53.330 block.go:Debug:280 → Segment: git [TRACE] 02:49:53.330 shell.go:Pwd() - 60ns [TRACE] 02:49:53.330 shell.go:GOOS() - 40ns [DEBUG] 02:49:53.330 shell_unix.go:IsWsl:35 → true [TRACE] 02:49:53.330 shell_unix.go:IsWsl() - 2.044µs [DEBUG] 02:49:53.330 shell.go:FileContent:523 ↓ 5.15.90.1-microsoft-standard-WSL2 [TRACE] 02:49:53.330 shell.go:FileContent(/proc/sys/kernel/osrelease) - 40.387µs [TRACE] 02:49:53.330 shell_unix.go:IsWsl2() - 47.01µs [TRACE] 02:49:53.330 shell.go:Pwd() - 60ns [DEBUG] 02:49:53.331 shell.go:RunCommand:579 → //wsl.localhost/Ubuntu/home/sfm61319 [TRACE] 02:49:53.331 shell.go:RunCommand(wslpath -m /home/sfm61319) - 453.401µs [TRACE] 02:49:53.331 shell.go:GOOS() - 50ns [DEBUG] 02:49:53.331 shell.go:CommandPath:600 → /usr/bin/git [TRACE] 02:49:53.331 shell.go:CommandPath(git) - 19.437µs [TRACE] 02:49:53.331 shell.go:HasCommand(git) - 23.675µs [TRACE] 02:49:53.331 shell.go:Pwd() - 100ns [ERROR] 02:49:53.331 shell.go:HasParentFilePath:733 → stat .git: no such file or directory [TRACE] 02:49:53.331 shell.go:HasParentFilePath(.git) - 17.393µs [DEBUG] 02:49:53.331 properties.go:GetBool:22 → fetch_bare_info: false [TRACE] 02:49:53.331 shell.go:Flags() - 40ns [DEBUG] 02:49:53.331 block.go:Debug:280 → Segment: text [TRACE] 02:49:53.331 shell.go:Pwd() - 40ns [TRACE] 02:49:53.331 shell.go:GOOS() - 40ns [TRACE] 02:49:53.331 shell.go:TemplateCache() - 120ns [TRACE] 02:49:53.331 shell.go:Shell() - 101ns [DEBUG] 02:49:53.331 shell.go:Getenv:398 → NO DATA [TRACE] 02:49:53.331 shell.go:Getenv(XDG_CACHE_HOME) - 2.805µs [TRACE] 02:49:53.331 shell_unix.go:CachePath() - 10.651µs [TRACE] 02:49:53.331 shell.go:Flags() - 40ns ```
SFM61319 commented 1 year ago

This is an issue because automated/UI tasks on editors like Visual Studio Code write commands to the terminal immediately after spawning it. This leads to the commands simply being read and discarded instead of being executed (because of Oh My Posh). Not using Oh My Posh (by removing eval "$(oh-my-posh init bash --config /mnt/c/Users/Svass/AppData/Local/Programs/oh-my-posh/themes/sigma.omp.json)" from the ~/.bashrc file) fixes this problem, but that defeats the whole purpose of using Oh My Posh.


Unrelated question: Are there plans to migrate to Rust anytime in the future?

JanDeDobbeleer commented 1 year ago

@SFM61319 how can I reproduce this? All oh-my-posh does is overwrite the prompt, nothing else. So if they decide to hook into something, expecting certain preconditions (they do the exact same thing with their shell integration scripts), that can lead to unwanted side effects.

Are there plans to migrate to Rust anytime in the future?

Not at all, there's no benefit in doing that.

SFM61319 commented 1 year ago

@SFM61319 how can I reproduce this? All oh-my-posh does is overwrite the prompt, nothing else. So if they decide to hook into something, expecting certain preconditions (they do the exact same thing with their shell integration scripts), that can lead to unwanted side effects.

One way to reproduce this is entering a command as soon as you launch a new terminal instance, before the first prompt is printed. If you missed it, you can also delay the next prompt (sleep <seconds>) and enter a command before the next prompt is printed. You can try these with Oh My Posh first enabled, then disabled.

Are there plans to migrate to Rust anytime in the future?

Not at all, there's no benefit in doing that.

Ah, cool.

SFM61319 commented 1 year ago

https://github.com/JanDeDobbeleer/oh-my-posh/assets/45308169/f7f34556-1b02-4dd8-ad62-6f3bed8a81db

https://github.com/JanDeDobbeleer/oh-my-posh/assets/45308169/df8da12a-4cc5-4351-9ecb-f4951e8aad81

SFM61319 commented 1 year ago

OhMyPosh_Enabled_Compressed.mp4 OhMyPosh_Disabled_Compressed.mp4

@JanDeDobbeleer (in case you weren't notified of my replies earlier, apologies for the mention).

JanDeDobbeleer commented 1 year ago

@SFM61319 I saw them. Just didn't have time to check just yet. I'm working on another issue ATM as this isn't a critical bug per se.

JanDeDobbeleer commented 1 year ago

@SFM61319 I can't reproduce this in bash 5.2.15 on my end. Are you on the latest bash?

SFM61319 commented 1 year ago

@SFM61319 I can't reproduce this in bash 5.2.15 on my end. Are you on the latest bash?

@JanDeDobbeleer I'm using GNU bash, version 5.1.16(1)-release (x86_64-pc-linux-gnu) on Ubuntu (WSL2).

JanDeDobbeleer commented 1 year ago

@SFM61319 can you upgrade to the latest and try again? That version is a few years old already.

SFM61319 commented 1 year ago

@JanDeDobbeleer I have just upgraded my Ubuntu WSL2 installation to 23.04. Also upgraded all my packages (including bash) to the latest lunar updates. WSL2 itself is already up-to-date.

My current bash version is GNU bash, version 5.2.15(1)-release (x86_64-pc-linux-gnu), and I am still encountering the same problem. Are you sure you tried Oh My Posh using the config I provided?

Ubuntu upgrade commands ```bash sudo sed -i "s/Prompt=lts/Prompt=normal/g" "/etc/update-manager/release-upgrades" sudo sed -i "s/jammy/lunar/g" "/etc/apt/sources.list" sudo apt update -y sudo apt upgrade -y sudo apt dist-upgrade -y sudo apt full-upgrade -y sudo apt autoremove -y sudo apt autoclean -y ```
JanDeDobbeleer commented 1 year ago

@SFM61319 guilty as charged. I used my own config. Will try again.

SFM61319 commented 1 year ago

@JanDeDobbeleer I have reencountered the issue. I am on the latest version of OhMyPosh (v18.6.0), the newest version of Bash and Ubuntu on WSL2, and have the latest versions of all (direct and indirect) dependencies. I request you to reopen this issue.

JanDeDobbeleer commented 1 year ago

@SFM61319 nothing changed in this implementation since this fix.

SFM61319 commented 1 year ago

@SFM61319 nothing changed in this implementation since this fix.

I didn't test the fix on my side after updating OhMyPosh (because I simply trusted the fixed release). But today when I tried to debug a C++ program on Visual Studio Code, it didn't run because VS Code was writing the debug command to the terminal before the first OhMyPosh prompt got printed (which was the same issue as before).

JanDeDobbeleer commented 1 year ago

@SFM61319 but did you add the correct setting to your configuration?

SFM61319 commented 1 year ago

@SFM61319 but did you add the correct setting to your configuration?

@JanDeDobbeleer I haven't changed my configuration, it's exactly the same as the one I sent previously to reproduce the bug. What do you mean by the correct configuration?

SFM61319 commented 1 year ago

@JanDeDobbeleer Nevermind, adding "disable_cursor_positioning": true to the configuration fixed it. That was really silly of me. Anyway, thank you for taking the time to reply.

github-actions[bot] commented 6 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.