JanDeDobbeleer / oh-my-posh

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

Status segment doesn't work in iTerm2 with bash shell integration enabled #4157

Closed klobetime closed 1 year ago

klobetime commented 1 year ago

Code of Conduct

What happened?

I'm using iTerm2 (build 3.4.20) on macOS Monterey (v12.6.7) and have enabled shell integration for bash (v5.2.15(1)-release). This combination apparently results in a non-zero exit code not being recognized:

Screen Shot 2023-08-14 at 11 08 17 AM

Using iTerm2 without the integration causes oh-my-posh to behave as expected.

I get that the shell integration could be affecting how the exit code is picked up and/or interpreted, but I don't see why bash can see there is an error code of 127 (in the screenshot above) but os-my-posh does not.

Theme

{
  "$schema":"https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json",
  "blocks":[
    {
      "alignment":"left",
      "segments":[
        {
          "foreground":"#00ff00",
          "foreground_templates":[
            "{{ if gt .Code 0 }}#ef5350{{ end }}"
          ],
          "properties":{
            "always_enabled":true
          },
          "style":"plain",
          "template":"\ue285\ue285",
          "type":"status"
        }
      ],
      "type":"prompt"
    }
  ],
  "version":2
}

What OS are you seeing the problem on?

macOS

Which shell are you using?

bash

Log output

Version: 18.3.3

Shell: bash (5.2.15(1)-release)

Prompt:



Segments:

ConsoleTitle(false)                       -   0 ms
Status(true)                              -   0 ms

Run duration: 2.260118ms

Cache path: /Users/klobetime/.cache/oh-my-posh

Config path: /Users/klobetime/simple.omp.json

Logs:

[DEBUG] 11:24:34.606 shell.go:Getenv:389 → iTerm.app
[TRACE] 11:24:34.606 shell.go:Getenv(TERM_PROGRAM) - 51.697µs
[DEBUG] 11:24:34.606 shell.go:Getenv:389 → NO DATA
[TRACE] 11:24:34.606 shell.go:Getenv(XDG_CACHE_HOME) - 3.568µs
[TRACE] 11:24:34.606 shell_unix.go:CachePath() - 47.467µs
[DEBUG] 11:24:34.606 shell.go:Getenv:389 → /Users/klobetime/simple.omp.json
[TRACE] 11:24:34.606 shell.go:Getenv(POSH_THEME) - 7.053µs
[DEBUG] 11:24:34.606 shell_unix.go:Platform:77 → darwin
[TRACE] 11:24:34.606 shell.go:resolveConfigPath() - 19.281µs
[TRACE] 11:24:34.606 shell.go:Init() - 362.86µs
[TRACE] 11:24:34.607 shell.go:Flags() - 300ns
[TRACE] 11:24:34.607 config.go:loadConfig() - 347.559µs
[TRACE] 11:24:34.607 shell.go:Flags() - 118ns
[DEBUG] 11:24:34.607 shell.go:Getenv:389 → NO DATA
[TRACE] 11:24:34.607 shell.go:Getenv(OMP_CACHE_DISABLED) - 3.605µs
[DEBUG] 11:24:34.607 shell.go:Shell:629 → no shell name provided in flags, trying to detect it
[DEBUG] 11:24:34.607 shell.go:Shell:637 → process name: bash
[TRACE] 11:24:34.607 shell.go:Shell() - 144.063µs
[DEBUG] 11:24:34.607 shell.go:Getenv:389 → 5.2.15(1)-release
[TRACE] 11:24:34.607 shell.go:Getenv(POSH_SHELL_VERSION) - 3.734µs
[DEBUG] 11:24:34.607 debug.go:PrintDebug:22 → Segment: Title
[DEBUG] 11:24:34.607 shell.go:Getenv:389 → NO DATA
[TRACE] 11:24:34.607 shell.go:Getenv(POSH_CURSOR_LINE) - 7.332µs
[DEBUG] 11:24:34.607 shell.go:Getenv:389 → NO DATA
[TRACE] 11:24:34.607 shell.go:Getenv(POSH_CURSOR_COLUMN) - 5.076µs
[TRACE] 11:24:34.607 shell.go:Flags() - 86ns
[TRACE] 11:24:34.607 shell.go:Flags() - 58ns
[TRACE] 11:24:34.607 shell.go:Shell() - 108ns
[TRACE] 11:24:34.607 shell.go:Flags() - 97ns
[DEBUG] 11:24:34.607 properties.go:GetString:28 → {{ .Code }}
[TRACE] 11:24:34.607 shell.go:GOOS() - 151ns
[DEBUG] 11:24:34.607 shell.go:Pwd:419 → /Users/klobetime
[TRACE] 11:24:34.607 shell.go:Pwd() - 23.504µs
[TRACE] 11:24:34.607 shell.go:GOOS() - 70ns
[DEBUG] 11:24:34.607 segment.go:SetEnabled:494 → Segment: Status
[TRACE] 11:24:34.607 shell.go:StatusCodes() - 203ns
[TRACE] 11:24:34.608 shell_unix.go:Root() - 1.275µs
[TRACE] 11:24:34.608 shell.go:Shell() - 145ns
[TRACE] 11:24:34.608 shell.go:StatusCodes() - 124ns
[DEBUG] 11:24:34.608 shell_unix.go:IsWsl:35 → false
[TRACE] 11:24:34.608 shell_unix.go:IsWsl() - 6.27µs
[DEBUG] 11:24:34.608 shell.go:TemplateCache:810 ↓
    environment: [SHELL=/usr/local/bin/bash ITERM_PROFILE=Default COLORTERM=truecolor XPC_FLAGS=0x0 HISTCONTROL=ignoredups:erasedups TERM_PROGRAM_VERSION=3.4.20 POSH_PID=34746 SDKMAN_OLD_PWD=/Users/klobetime HISTSIZE=8192 JAVA_HOME=/Users/klobetime/.sdkman/candidates/java/current __CFBundleIdentifier=com.googlecode.iterm2 SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.V5f9jwJDY2/Listeners TERM_SESSION_ID=w0t0p0:E8E62247-3891-47EA-B7BF-A5CA9554CDB5 ANT_HOME=/Users/klobetime/.sdkman/candidates/ant/current SDKMAN_CANDIDATES_DIR=/Users/klobetime/.sdkman/candidates ITERM_PREV_PS1=\[\]\[\]\[\]\[\] EDITOR=mvim -f ITERM_ORIG_PS1=\[\]\[\] PWD=/Users/klobetime LOGNAME=klobetime SELENIUM_ARCHIVE=/Users/klobetime/Documents/selenium_archive GREP_OPTIONS=--color=auto COMMAND_MODE=unix2003 ITERM_SESSION_ID=w0t0p0:E8E62247-3891-47EA-B7BF-A5CA9554CDB5 HOME=/Users/klobetime LANG=en_US.UTF-8 HISTFILE=/Users/klobetime/.history.34746 POSH_SHELL_VERSION=5.2.15(1)-release SDKMAN_VERSION=5.18.0 CONDA_PROMPT_MODIFIER=false TMPDIR=/var/folders/yw/vlr9zv8d4p9g7rrbx8dlc4ym0000gn/T/ PROMPT_COMMAND=__bp_precmd_invoke_cmd
    _omp_hook; history -a; history -r; history -r;sdkman_auto_env
    __iterm2_prompt_command
    __bp_interactive_mode LC_TERMINAL=iTerm2 SELENIUM_AUX=/Users/klobetime/Documents/selenium_aux BASH_SILENCE_DEPRECATION_WARNING=1 NVM_DIR=/Users/klobetime/.nvm TERM=xterm-256color USER=klobetime COLORFGBG=0;15 MAVEN_HOME=/Users/klobetime/.sdkman/candidates/maven/current VISUAL=mvim -f LC_TERMINAL_VERSION=3.4.20 SDKMAN_DIR=/Users/klobetime/.sdkman DISPLAY=/private/tmp/com.apple.launchd.8hl2Lbi4gX/org.macosforge.xquartz:0 SHLVL=1 NVM_CD_FLAGS= PAGER=vimpager SDKMAN_CANDIDATES_API=https://api.sdkman.io/2 XPC_SERVICE_NAME=0 POSH_THEME=/Users/klobetime/simple.omp.json PS1=\[\]\[\] PATH=/Users/klobetime/.sdkman/candidates/maven/current/bin:/Users/klobetime/.sdkman/candidates/java/current/bin:/Users/klobetime/.sdkman/candidates/ant/current/bin:/Users/klobetime/.nvm/versions/node/v18.17.0/bin:/Users/klobetime/bin:/usr/local/mysql/bin:/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Library/Apple/usr/bin:/Applications/WebStorm.app/Contents/MacOS:/Users/klobetime/Documents/selenium/client/testautomation/chromedriver SELENIUM_BASE=/Users/klobetime/Documents/selenium HISTIGNORE=&:exit:history SDKMAN_PLATFORM=darwinx64 NVM_BIN=/Users/klobetime/.nvm/versions/node/v18.17.0/bin POWERLINE_COMMAND=oh-my-posh __CF_USER_TEXT_ENCODING=0x1F5:0x0:0x0 TERM_PROGRAM=iTerm.app _=/usr/local/bin/oh-my-posh]
[TRACE] 11:24:34.608 shell.go:Pwd() - 209ns
[TRACE] 11:24:34.608 shell.go:GOOS() - 136ns
[TRACE] 11:24:34.608 shell.go:GOOS() - 82ns
[TRACE] 11:24:34.608 shell.go:GOOS() - 56ns
[TRACE] 11:24:34.608 shell.go:GOOS() - 60ns
[TRACE] 11:24:34.608 shell.go:GOOS() - 60ns
[TRACE] 11:24:34.608 shell.go:GOOS() - 58ns
[TRACE] 11:24:34.608 shell.go:GOOS() - 60ns
[TRACE] 11:24:34.608 shell.go:GOOS() - 57ns
[TRACE] 11:24:34.608 shell.go:GOOS() - 80ns
[TRACE] 11:24:34.608 shell.go:GOOS() - 57ns
[TRACE] 11:24:34.608 shell.go:GOOS() - 60ns
[DEBUG] 11:24:34.608 shell.go:User:540 → klobetime
[TRACE] 11:24:34.608 shell.go:User() - 3.925µs
[DEBUG] 11:24:34.608 shell.go:Host:552 → Klobes-MacBook-Pro
[TRACE] 11:24:34.608 shell.go:Host() - 16.443µs
[TRACE] 11:24:34.608 shell.go:GOOS() - 79ns
[DEBUG] 11:24:34.608 shell.go:Getenv:389 → 1
[TRACE] 11:24:34.608 shell.go:Getenv(SHLVL) - 3.371µs
[TRACE] 11:24:34.608 shell.go:TemplateCache() - 188.776µs
[DEBUG] 11:24:34.608 properties.go:GetBool:22 → always_enabled: true
[TRACE] 11:24:34.608 shell.go:TemplateCache() - 206ns
[TRACE] 11:24:34.608 shell.go:Shell() - 123ns
[TRACE] 11:24:34.608 shell.go:TemplateCache() - 223ns
[TRACE] 11:24:34.608 shell.go:Shell() - 241ns
[TRACE] 11:24:34.608 shell.go:Shell() - 76ns
[TRACE] 11:24:34.608 shell.go:Shell() - 92ns
[TRACE] 11:24:34.608 shell.go:Shell() - 61ns
[DEBUG] 11:24:34.608 shell.go:Getenv:389 → NO DATA
[TRACE] 11:24:34.608 shell.go:Getenv(XDG_CACHE_HOME) - 3.464µs
[TRACE] 11:24:34.608 shell_unix.go:CachePath() - 25.061µs
[TRACE] 11:24:34.608 shell.go:Flags() - 117ns
JanDeDobbeleer commented 1 year ago

@klobetime because they hijack the prompt function again, so it's pretty unreliable. You're better off enabling shell integrations in oh-my-posh, instead of adding the terminal built-in scripts. Our integration is a lot more reliable.

JanDeDobbeleer commented 1 year ago

@klobetime you can set shell_integration to true in the config.

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