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

PowerShell $LASTEXITCODE not caught by 'exit' segment #2665

Closed rlove closed 2 years ago

rlove commented 2 years ago

Code of Conduct

What happened?

Running these 3 commands in a new powershell core (on windows OS) session.

run cmd.exe /c "exit 0" expected error exit.code == 0 actual exit.code == 0 run cmd.exe /c "exit 44" expected error exit.code > 0 actual exit.code == 0 run throw "asdf" expected error exit.code > 0 actual exit.code > 0

I think it's due to the strange way exit codes for external processes can work in powershell. https://stackoverflow.com/questions/57468522/powershell-and-process-exit-codes

Theme

{
  "$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json",
  "blocks": [
    {
      "alignment": "left",
      "segments": [
        {
          "background": "p:red",
          "foreground": "p:white",
          "powerline_symbol": "\ue0b0",
          "properties": {
            "home_icon": "\uf415\\",
            "style": "full",
            "mapped_locations": {
              "C:\\": ""
            }
          },
          "style": "powerline",
          "template": "{{ path .Path .Location }} ",
          "type": "path"
        },
        {
          "background": "p:green",
          "background_templates": [
            "{{ if or (.Working.Changed) (.Staging.Changed) }}p:yellow{{ end }}",
            "{{ if and (gt .Ahead 0) (gt .Behind 0) }}p:red{{ end }}",
            "{{ if gt .Ahead 0 }}#49416D{{ end }}",
            "{{ if gt .Behind 0 }}#7A306C{{ end }}"
          ],
          "foreground": "p:black",
          "foreground_templates": [
            "{{ if or (.Working.Changed) (.Staging.Changed) }}p:black{{ end }}",
            "{{ if and (gt .Ahead 0) (gt .Behind 0) }}p:white{{ end }}",
            "{{ if gt .Ahead 0 }}p:white{{ end }}"
          ],
          "powerline_symbol": "\ue0b0",
          "properties": {
            "branch_max_length": 25,
            "fetch_status": true,
            "fetch_upstream_icon": true,
            "github_icon": "\uf7a3"
          },
          "style": "powerline",
          "template": " {{ if .UpstreamURL }}{{ url .UpstreamIcon .UpstreamURL }} {{ end }}{{ .HEAD }}{{ .BranchStatus }}{{ if .Working.Changed }} \uf044 {{ .Working.String }}{{ end }}{{ if .Staging.Changed }} \uf046 {{ .Staging.String }}{{ end }} ",
          "type": "git"
        },
        {
          "background": "p:yellow",
          "foreground": "p:white",
          "powerline_symbol": "\ue0b0",
          "properties": {
            "root_icon": "\uf0ad"
          },
          "style": "powerline",
          "template": " \uf0e7 ",
          "type": "root"
        },
        {
          "background": "p:blue",
          "background_templates": [
            "{{ if gt .Code 0 }}p:red{{ end }}"
          ],
          "foreground": "p:white",
          "leading_diamond": "<transparent,background>\ue0b0</>",
          "properties": {
            "always_enabled": true
          },
          "style": "diamond",
          "template": " {{ if gt .Code 0 }}\uf00d{{ else }}\uf00c{{ end }} ",
          "trailing_diamond": "\ue0b4",
          "type": "exit"
        }
      ],
      "type": "prompt"
    },
    {
      "segments": [
        {
          "background": "transparent",
          "foreground": "p:green",
          "properties": {
            "display_mode": "files",
            "fetch_package_manager": false,
            "home_enabled": false
          },
          "style": "plain",
          "template": "\uf898 ",
          "type": "node"
        },
        {
          "background": "transparent",
          "foreground": "p:blue",
          "properties": {
            "fetch_version": false
          },
          "style": "powerline",
          "template": "\ufcd1 ",
          "type": "go"
        },
        {
          "background": "transparent",
          "foreground": "p:yellow",
          "properties": {
            "display_mode": "files",
            "fetch_version": true,
            "fetch_virtual_env": false
          },
          "style": "plain",
          "template": "\ue235 ",
          "type": "python"
        },
        {
          "background": "transparent",
          "foreground": "p:white",
          "style": "plain",
          "template": "in <p:blue><b>{{ .Name }}</b></> ",
          "type": "shell"
        },
        {
          "background": "transparent",
          "foreground": "p:white",
          "style": "plain",
          "template": "at <p:blue><b>{{ .CurrentDate | date \"3:04.5 PM\" }}</b></>",
          "type": "time"
        }
      ],
      "type": "rprompt"
    }
  ],
  "console_title_template": "{{ .Shell }} in {{ .Folder }} ({{ .Env.AWS_PROFILE }})",
  "final_space": true,
  "palette": {
    "black": "#262B44",
    "blue": "#4B95E9",
    "green": "#59C9A5",
    "orange": "#F07623",
    "red": "#D81E5B",
    "white": "#E0DEF4",
    "yellow": "#F3AE35"
  },
  "secondary_prompt": {
    "background": "transparent",
    "foreground": "p:black",
    "template": "<p:yellow,transparent>\ue0b6</><,p:yellow> > </><p:yellow,transparent>\ue0b0</> "
  },
  "tooltips": [
    {
      "background": "p:orange",
      "foreground": "p:white",
      "leading_diamond": "\ue0b6",
      "properties": {
        "display_default": true
      },
      "style": "diamond",
      "template": " \ue7ad {{ .Profile }}{{ if .Region }}@{{ .Region }}{{ end }} ",
      "tips": [
        "aws"
      ],
      "trailing_diamond": "\ue0b4",
      "type": "aws"
    },
    {
      "background": "p:blue",
      "foreground": "p:white",
      "leading_diamond": "\ue0b6",
      "style": "diamond",
      "template": " \ufd03 {{ .Name }} ",
      "tips": [
        "az"
      ],
      "trailing_diamond": "\ue0b4",
      "type": "az"
    }
  ],
  "transient_prompt": {
    "background": "transparent",
    "foreground": "p:black",
    "template": "<p:yellow,transparent>\ue0b6</><,p:yellow> {{ .Folder }} </><p:yellow,transparent>\ue0b0</> "
  },
  "version": 2
}

What OS are you seeing the problem on?

Windows

Which shell are you using?

powershell

Log output

Version: 8.30.0

Segments:

ConsoleTitle(true) -   0 ms - pwsh in dev (qa)
path(true)    -   0 ms - dev
git(false)    -  12 ms -
root(false)   -   0 ms -
exit(true)    -   0 ms -   
node(false)   -   0 ms -
go(false)     -   1 ms -
python(false) -   0 ms -
shell(true)   -   1 ms - in pwsh
time(true)    -   0 ms - at 9:28.23 PM

Run duration: 43.7135ms

Cache path: C:\Users\rlove\AppData\Local\oh-my-posh

Config path: C:\users\rlove\.rlove.omp.json

Logs:

2022/08/15 21:28:23 debug: Getenv
C:\Users\rlove\AppData\Local
2022/08/15 21:28:23 Getenv duration: 0s, args: LOCALAPPDATA
2022/08/15 21:28:23 CachePath duration: 0s, args:
2022/08/15 21:28:23 debug: Getenv
C:\users\rlove\.rlove.omp.json
2022/08/15 21:28:23 Getenv duration: 0s, args: POSH_THEME
2022/08/15 21:28:23 Shell duration: 15.9245ms, args:
2022/08/15 21:28:23 resolveConfigPath duration: 15.9245ms, args:
2022/08/15 21:28:23 Init duration: 26.2631ms, args:
2022/08/15 21:28:23 Flags duration: 0s, args:
2022/08/15 21:28:23 config.loadConfig duration: 1.0561ms, args:
2022/08/15 21:28:23 Flags duration: 0s, args:
2022/08/15 21:28:23 debug: Getenv

2022/08/15 21:28:23 Getenv duration: 14.7µs, args: OMP_CACHE_DISABLED
2022/08/15 21:28:23 WindowsRegistryKeyValue duration: 0s, args: HKEY_CURRENT_USER\Software\Microsoft\Windows\DWM\ColorizationColor
2022/08/15 21:28:23 PathSeparator duration: 0s, args:
2022/08/15 21:28:23 PathSeparator duration: 0s, args:
2022/08/15 21:28:23 PathSeparator duration: 0s, args:
2022/08/15 21:28:23 PathSeparator duration: 0s, args:
2022/08/15 21:28:23 PathSeparator duration: 0s, args:
2022/08/15 21:28:23 PathSeparator duration: 0s, args:
2022/08/15 21:28:23 PathSeparator duration: 0s, args:
2022/08/15 21:28:23 PathSeparator duration: 0s, args:
2022/08/15 21:28:23 PathSeparator duration: 0s, args:
2022/08/15 21:28:23 PathSeparator duration: 0s, args:
2022/08/15 21:28:23 PathSeparator duration: 0s, args:
2022/08/15 21:28:23 PathSeparator duration: 0s, args:
2022/08/15 21:28:23 PathSeparator duration: 0s, args:
2022/08/15 21:28:23 PathSeparator duration: 0s, args:
2022/08/15 21:28:23 PathSeparator duration: 0s, args:
2022/08/15 21:28:23 PathSeparator duration: 0s, args:
2022/08/15 21:28:23 PathSeparator duration: 0s, args:
2022/08/15 21:28:23 PathSeparator duration: 0s, args:
2022/08/15 21:28:23 PathSeparator duration: 0s, args:
2022/08/15 21:28:23 debug: WindowsRegistryKeyValue
ColorizationColor(DWORD): 0xC40078D7
2022/08/15 21:28:23 Root duration: 0s, args:
2022/08/15 21:28:23 Shell duration: 0s, args:
2022/08/15 21:28:23 ErrorCode duration: 0s, args:
2022/08/15 21:28:23 IsWsl duration: 0s, args:
2022/08/15 21:28:23 debug: Pwd
C:\dev
2022/08/15 21:28:23 Pwd duration: 0s, args:
2022/08/15 21:28:23 debug: Home
C:\users\rlove\
2022/08/15 21:28:23 PathSeparator duration: 0s, args:
2022/08/15 21:28:23 PathSeparator duration: 0s, args:
2022/08/15 21:28:23 PathSeparator duration: 0s, args:
2022/08/15 21:28:23 PathSeparator duration: 0s, args:
2022/08/15 21:28:23 PathSeparator duration: 0s, args:
2022/08/15 21:28:23 debug: User
rlove
2022/08/15 21:28:23 User duration: 0s, args:
2022/08/15 21:28:23 debug: Host
SEDTS-L1LF-3KK9
2022/08/15 21:28:23 Host duration: 0s, args:
2022/08/15 21:28:23 GOOS duration: 0s, args:
2022/08/15 21:28:23 TemplateCache duration: 0s, args:
2022/08/15 21:28:23 Flags duration: 0s, args:
2022/08/15 21:28:23 debug: Pwd
C:\dev
2022/08/15 21:28:23 Pwd duration: 0s, args:
2022/08/15 21:28:23 debug: Home
C:\users\rlove\
2022/08/15 21:28:23 GOOS duration: 0s, args:
2022/08/15 21:28:23 debug: Pwd
C:\dev
2022/08/15 21:28:23 Pwd duration: 0s, args:
2022/08/15 21:28:23 Flags duration: 0s, args:
2022/08/15 21:28:23 debug: Pwd
C:\dev
2022/08/15 21:28:23 Pwd duration: 0s, args:
2022/08/15 21:28:23 debug: Home
C:\users\rlove\
2022/08/15 21:28:23 GOOS duration: 0s, args:
2022/08/15 21:28:23 GOOS duration: 0s, args:
2022/08/15 21:28:23 GOOS duration: 0s, args:
2022/08/15 21:28:23 PathSeparator duration: 0s, args:
2022/08/15 21:28:23 PathSeparator duration: 0s, args:
2022/08/15 21:28:23 GOOS duration: 0s, args:
2022/08/15 21:28:23 IsWsl duration: 0s, args:
2022/08/15 21:28:23 StackCount duration: 0s, args:
2022/08/15 21:28:23 DirIsWritable duration: 527.1µs, args:
2022/08/15 21:28:23 TemplateCache duration: 0s, args:
2022/08/15 21:28:23 TemplateCache duration: 0s, args:
2022/08/15 21:28:23 Shell duration: 0s, args:
2022/08/15 21:28:23 debug: Pwd
C:\dev
2022/08/15 21:28:23 Pwd duration: 0s, args:
2022/08/15 21:28:23 debug: Home
C:\users\rlove\
2022/08/15 21:28:23 GOOS duration: 0s, args:
2022/08/15 21:28:23 GOOS duration: 0s, args:
2022/08/15 21:28:23 debug: CommandPath
C:\Program Files\Git\cmd\git.exe
2022/08/15 21:28:23 CommandPath duration: 11.2818ms, args: git.exe
2022/08/15 21:28:23 HasCommand duration: 11.2818ms, args: git.exe
2022/08/15 21:28:23 debug: Pwd
C:\dev
2022/08/15 21:28:23 Pwd duration: 0s, args:
2022/08/15 21:28:23 error: HasParentFilePath
CreateFile C:\.git: The system cannot find the file specified.
2022/08/15 21:28:23 HasParentFilePath duration: 1.0086ms, args: .git
2022/08/15 21:28:23 debug: Pwd
C:\dev
2022/08/15 21:28:23 Pwd duration: 0s, args:
2022/08/15 21:28:23 debug: Home
C:\users\rlove\
2022/08/15 21:28:23 GOOS duration: 0s, args:
2022/08/15 21:28:23 Root duration: 0s, args:
2022/08/15 21:28:23 debug: Pwd
C:\dev
2022/08/15 21:28:23 Pwd duration: 0s, args:
2022/08/15 21:28:23 debug: Home
C:\users\rlove\
2022/08/15 21:28:23 GOOS duration: 0s, args:
2022/08/15 21:28:23 ErrorCode duration: 0s, args:
2022/08/15 21:28:23 TemplateCache duration: 0s, args:
2022/08/15 21:28:23 TemplateCache duration: 0s, args:
2022/08/15 21:28:23 Shell duration: 0s, args:
2022/08/15 21:28:23 TemplateCache duration: 0s, args:
2022/08/15 21:28:23 Flags duration: 0s, args:
2022/08/15 21:28:23 debug: Pwd
C:\dev
2022/08/15 21:28:23 Pwd duration: 0s, args:
2022/08/15 21:28:23 debug: Home
C:\users\rlove\
2022/08/15 21:28:23 GOOS duration: 0s, args:
2022/08/15 21:28:23 debug: Pwd
C:\dev
2022/08/15 21:28:23 Pwd duration: 0s, args:
2022/08/15 21:28:23 debug: Home
C:\users\rlove\
2022/08/15 21:28:23 debug: Pwd
C:\dev
2022/08/15 21:28:23 Pwd duration: 0s, args:
2022/08/15 21:28:23 PathSeparator duration: 0s, args:
2022/08/15 21:28:23 debug: HasFiles
false
2022/08/15 21:28:23 HasFiles duration: 0s, args: *.js
2022/08/15 21:28:23 debug: Pwd
C:\dev
2022/08/15 21:28:23 Pwd duration: 0s, args:
2022/08/15 21:28:23 PathSeparator duration: 0s, args:
2022/08/15 21:28:23 debug: HasFiles
false
2022/08/15 21:28:23 HasFiles duration: 0s, args: *.ts
2022/08/15 21:28:23 debug: Pwd
C:\dev
2022/08/15 21:28:23 Pwd duration: 0s, args:
2022/08/15 21:28:23 PathSeparator duration: 0s, args:
2022/08/15 21:28:23 debug: HasFiles
false
2022/08/15 21:28:23 HasFiles duration: 0s, args: package.json
2022/08/15 21:28:23 debug: Pwd
C:\dev
2022/08/15 21:28:23 Pwd duration: 0s, args:
2022/08/15 21:28:23 PathSeparator duration: 0s, args:
2022/08/15 21:28:23 debug: HasFiles
false
2022/08/15 21:28:23 HasFiles duration: 0s, args: .nvmrc
2022/08/15 21:28:23 debug: Pwd
C:\dev
2022/08/15 21:28:23 Pwd duration: 0s, args:
2022/08/15 21:28:23 PathSeparator duration: 0s, args:
2022/08/15 21:28:23 debug: HasFiles
false
2022/08/15 21:28:23 HasFiles duration: 0s, args: pnpm-workspace.yaml
2022/08/15 21:28:23 debug: Pwd
C:\dev
2022/08/15 21:28:23 Pwd duration: 0s, args:
2022/08/15 21:28:23 PathSeparator duration: 0s, args:
2022/08/15 21:28:23 debug: HasFiles
false
2022/08/15 21:28:23 HasFiles duration: 0s, args: .pnpmfile.cjs
2022/08/15 21:28:23 debug: Pwd
C:\dev
2022/08/15 21:28:23 Pwd duration: 0s, args:
2022/08/15 21:28:23 PathSeparator duration: 0s, args:
2022/08/15 21:28:23 debug: HasFiles
false
2022/08/15 21:28:23 HasFiles duration: 0s, args: .npmrc
2022/08/15 21:28:23 debug: Pwd
C:\dev
2022/08/15 21:28:23 Pwd duration: 0s, args:
2022/08/15 21:28:23 PathSeparator duration: 0s, args:
2022/08/15 21:28:23 debug: HasFiles
false
2022/08/15 21:28:23 HasFiles duration: 0s, args: .vue
2022/08/15 21:28:23 debug: Pwd
C:\dev
2022/08/15 21:28:23 Pwd duration: 0s, args:
2022/08/15 21:28:23 debug: Home
C:\users\rlove\
2022/08/15 21:28:23 GOOS duration: 0s, args:
2022/08/15 21:28:23 debug: Pwd
C:\dev
2022/08/15 21:28:23 Pwd duration: 0s, args:
2022/08/15 21:28:23 debug: Home
C:\users\rlove\
2022/08/15 21:28:23 debug: Pwd
C:\dev
2022/08/15 21:28:23 Pwd duration: 0s, args:
2022/08/15 21:28:23 PathSeparator duration: 0s, args:
2022/08/15 21:28:23 debug: HasFiles
false
2022/08/15 21:28:23 HasFiles duration: 1.8192ms, args: *.go
2022/08/15 21:28:23 debug: Pwd
C:\dev
2022/08/15 21:28:23 Pwd duration: 0s, args:
2022/08/15 21:28:23 PathSeparator duration: 0s, args:
2022/08/15 21:28:23 debug: HasFiles
false
2022/08/15 21:28:23 HasFiles duration: 0s, args: go.mod
2022/08/15 21:28:23 debug: Pwd
C:\dev
2022/08/15 21:28:23 Pwd duration: 0s, args:
2022/08/15 21:28:23 debug: Home
C:\users\rlove\
2022/08/15 21:28:23 GOOS duration: 0s, args:
2022/08/15 21:28:23 debug: Pwd
C:\dev
2022/08/15 21:28:23 Pwd duration: 0s, args:
2022/08/15 21:28:23 debug: Home
C:\users\rlove\
2022/08/15 21:28:23 debug: Pwd
C:\dev
2022/08/15 21:28:23 Pwd duration: 0s, args:
2022/08/15 21:28:23 PathSeparator duration: 0s, args:
2022/08/15 21:28:23 debug: HasFiles
false
2022/08/15 21:28:23 HasFiles duration: 0s, args: *.py
2022/08/15 21:28:23 debug: Pwd
C:\dev
2022/08/15 21:28:23 Pwd duration: 0s, args:
2022/08/15 21:28:23 PathSeparator duration: 0s, args:
2022/08/15 21:28:23 debug: HasFiles
false
2022/08/15 21:28:23 HasFiles duration: 0s, args: *.ipynb
2022/08/15 21:28:23 debug: Pwd
C:\dev
2022/08/15 21:28:23 Pwd duration: 0s, args:
2022/08/15 21:28:23 PathSeparator duration: 0s, args:
2022/08/15 21:28:23 debug: HasFiles
false
2022/08/15 21:28:23 HasFiles duration: 0s, args: pyproject.toml
2022/08/15 21:28:23 debug: Pwd
C:\dev
2022/08/15 21:28:23 Pwd duration: 0s, args:
2022/08/15 21:28:23 PathSeparator duration: 0s, args:
2022/08/15 21:28:23 debug: HasFiles
false
2022/08/15 21:28:23 HasFiles duration: 0s, args: venv.bak
2022/08/15 21:28:23 debug: HasFolder
false
2022/08/15 21:28:23 HasFolder duration: 0s, args: .venv
2022/08/15 21:28:23 debug: HasFolder
false
2022/08/15 21:28:23 HasFolder duration: 0s, args: venv
2022/08/15 21:28:23 debug: HasFolder
false
2022/08/15 21:28:23 HasFolder duration: 0s, args: virtualenv
2022/08/15 21:28:23 debug: HasFolder
false
2022/08/15 21:28:23 HasFolder duration: 0s, args: env
2022/08/15 21:28:23 debug: HasFolder
false
2022/08/15 21:28:23 HasFolder duration: 0s, args: venv-win
2022/08/15 21:28:23 debug: HasFolder
false
2022/08/15 21:28:23 HasFolder duration: 0s, args: pyenv-win
2022/08/15 21:28:23 debug: Pwd
C:\dev
2022/08/15 21:28:23 Pwd duration: 0s, args:
2022/08/15 21:28:23 debug: Home
C:\users\rlove\
2022/08/15 21:28:23 GOOS duration: 0s, args:
2022/08/15 21:28:23 Shell duration: 0s, args:
2022/08/15 21:28:23 Flags duration: 0s, args:
2022/08/15 21:28:23 TemplateCache duration: 0s, args:
2022/08/15 21:28:23 TemplateCache duration: 0s, args:
2022/08/15 21:28:23 Shell duration: 0s, args:
2022/08/15 21:28:23 debug: Pwd
C:\dev
2022/08/15 21:28:23 Pwd duration: 0s, args:
2022/08/15 21:28:23 debug: Home
C:\users\rlove\
2022/08/15 21:28:23 GOOS duration: 0s, args:
2022/08/15 21:28:23 TemplateCache duration: 0s, args:
2022/08/15 21:28:23 TemplateCache duration: 0s, args:
2022/08/15 21:28:23 Shell duration: 0s, args:
2022/08/15 21:28:23 debug: Getenv
C:\Users\rlove\AppData\Local
2022/08/15 21:28:23 Getenv duration: 0s, args: LOCALAPPDATA
2022/08/15 21:28:23 CachePath duration: 0s, args:
2022/08/15 21:28:23 Flags duration: 0s, args:
lewis-yeung commented 2 years ago

run cmd.exe /c "exit 44" expected error exit.code > 0 actual exit.code == 0

I cannot reproduce this case on my end. The exit code is 44 as expected.

EDITED: $global:LASTEXITCODE may have been changed by something other than the prompt function defined by Oh My Posh.

JanDeDobbeleer commented 2 years ago

@rlove which version of PowerShell Core is this? We did a lot of work on this as indeed, it's not very straightforward, but if @lewis-yeung can't reproduce it (who did amazing work on the PowerShell) we're a bit stuck. Do you still have this behavior with a clean profile that only initializes oh-my-posh?

rlove commented 2 years ago

@lewis-yeung & @JanDeDobbeleer thank you. The problem is specific to something in my profile. When I comment out everything other than oh-my-posh in my profile it works fine. I suspect I did not remove 100% of my custom prompt code that I wrote, which did work with $LASTEXITCODE

Thanks for producing something that allows me to ditch my custom code.

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.