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

[fish] Exit code not working #2485

Closed bend-n closed 2 years ago

bend-n commented 2 years ago

Code of Conduct

What happened?

Exit code segment always 0

fish: fish bash: bash

Theme

{
  "background": "p:blue",
  "background_templates": [
    "{{ if gt .Code 0 }}p:red{{ end }}"
  ],
  "foreground": "p:white",
  "powerline_symbol": "",
  "properties": {
    "always_enabled": true
  },
  "style": "diamond",
  "template": " {{ if gt .Code 0 }} {{ .Meaning }}{{ else }}{{ end }} ",
  "trailing_diamond": "",
  "type": "exit"
}

What OS are you seeing the problem on?

Linux

Which shell are you using?

fish

Log output

Version: 8.11.1

Segments:

ConsoleTitle(true)   -  16 ms - fish::~
session(true)        -   0 ms -  bendn@klunk 
path(true)           -   0 ms -    
command(false)       -  16 ms - 
executiontime(true)  -   0 ms -  羽0ms 
exit(true)           -   0 ms -   
shell(true)          -   0 ms -   fish 
command(true)        -  61 ms -  08:59滛  (28.99°C) feels 34.5°C (c) 

Run duration: 98.960315ms

Cache path: /home/bendn/.cache/oh-my-posh

Config path: /home/bendn/prompt.omp.json

Logs:

2022/07/05 08:59:58 debug: Getenv

2022/07/05 08:59:58 Getenv duration: 23.091µs, args: XDG_CACHE_HOME
2022/07/05 08:59:58 CachePath duration: 71.002µs, args: 
2022/07/05 08:59:58 debug: Getenv
/home/bendn/prompt.omp.json
2022/07/05 08:59:58 Getenv duration: 4.873µs, args: POSH_THEME
2022/07/05 08:59:58 resolveConfigPath duration: 18.33µs, args: 
2022/07/05 08:59:58 Init duration: 226.23µs, args: 
2022/07/05 08:59:58 Flags duration: 371ns, args: 
2022/07/05 08:59:58 config.loadConfig duration: 905.391µs, args: 
2022/07/05 08:59:58 Flags duration: 106ns, args: 
2022/07/05 08:59:58 debug: Getenv

2022/07/05 08:59:58 Getenv duration: 2.784µs, args: OMP_CACHE_DISABLED
2022/07/05 08:59:58 Root duration: 1.721µs, args: 
2022/07/05 08:59:58 Shell duration: 15.765074ms, args: 
2022/07/05 08:59:58 ErrorCode duration: 318ns, args: 
2022/07/05 08:59:58 debug: Getenv

2022/07/05 08:59:58 Getenv duration: 4.321µs, args: WSL_DISTRO_NAME
2022/07/05 08:59:58 IsWsl duration: 10.23µs, args: 
2022/07/05 08:59:58 debug: Pwd
/home/bendn
2022/07/05 08:59:58 Pwd duration: 46.823µs, args: 
2022/07/05 08:59:58 PathSeparator duration: 106ns, args: 
2022/07/05 08:59:58 PathSeparator duration: 63ns, args: 
2022/07/05 08:59:58 debug: User
bendn
2022/07/05 08:59:58 User duration: 2.572µs, args: 
2022/07/05 08:59:58 debug: Host
klunk
2022/07/05 08:59:58 Host duration: 7.926µs, args: 
2022/07/05 08:59:58 GOOS duration: 102ns, args: 
2022/07/05 08:59:58 TemplateCache duration: 15.950989ms, args: 
2022/07/05 08:59:58 Flags duration: 183ns, args: 
2022/07/05 08:59:58 debug: Pwd
/home/bendn
2022/07/05 08:59:58 Pwd duration: 3.99µs, args: 
2022/07/05 08:59:58 GOOS duration: 104ns, args: 
2022/07/05 08:59:58 debug: Getenv

2022/07/05 08:59:58 Getenv duration: 2.338µs, args: SSH_CONNECTION
2022/07/05 08:59:58 debug: Getenv

2022/07/05 08:59:58 Getenv duration: 1.998µs, args: SSH_CLIENT
2022/07/05 08:59:58 TemplateCache duration: 98ns, args: 
2022/07/05 08:59:58 TemplateCache duration: 241ns, args: 
2022/07/05 08:59:58 Shell duration: 304ns, args: 
2022/07/05 08:59:58 debug: Pwd
/home/bendn
2022/07/05 08:59:58 Pwd duration: 3.03µs, args: 
2022/07/05 08:59:58 GOOS duration: 106ns, args: 
2022/07/05 08:59:58 debug: Pwd
/home/bendn
2022/07/05 08:59:58 Pwd duration: 1.589µs, args: 
2022/07/05 08:59:58 Flags duration: 80ns, args: 
2022/07/05 08:59:58 debug: Pwd
/home/bendn
2022/07/05 08:59:58 Pwd duration: 2.221µs, args: 
2022/07/05 08:59:58 GOOS duration: 78ns, args: 
2022/07/05 08:59:58 GOOS duration: 56ns, args: 
2022/07/05 08:59:58 PathSeparator duration: 99ns, args: 
2022/07/05 08:59:58 PathSeparator duration: 64ns, args: 
2022/07/05 08:59:58 PathSeparator duration: 47ns, args: 
2022/07/05 08:59:58 PathSeparator duration: 48ns, args: 
2022/07/05 08:59:58 PathSeparator duration: 50ns, args: 
2022/07/05 08:59:58 PathSeparator duration: 50ns, args: 
2022/07/05 08:59:58 GOOS duration: 52ns, args: 
2022/07/05 08:59:58 debug: Getenv

2022/07/05 08:59:58 Getenv duration: 1.966µs, args: WSL_DISTRO_NAME
2022/07/05 08:59:58 IsWsl duration: 5.234µs, args: 
2022/07/05 08:59:58 StackCount duration: 92ns, args: 
2022/07/05 08:59:58 DirIsWritable duration: 13.971µs, args: 
2022/07/05 08:59:58 TemplateCache duration: 99ns, args: 
2022/07/05 08:59:58 TemplateCache duration: 224ns, args: 
2022/07/05 08:59:58 Shell duration: 153ns, args: 
2022/07/05 08:59:58 debug: Pwd
/home/bendn
2022/07/05 08:59:58 Pwd duration: 2.492µs, args: 
2022/07/05 08:59:58 GOOS duration: 106ns, args: 
2022/07/05 08:59:58 HasCommand duration: 83.354µs, args: bash
2022/07/05 08:59:58 debug: RunCommand

2022/07/05 08:59:58 RunCommand duration: 15.895177ms, args: bash -c git_branch
2022/07/05 08:59:58 RunShellCommand duration: 15.910819ms, args: bash git_branch
2022/07/05 08:59:58 debug: Pwd
/home/bendn
2022/07/05 08:59:58 Pwd duration: 4.2µs, args: 
2022/07/05 08:59:58 GOOS duration: 170ns, args: 
2022/07/05 08:59:58 ExecutionTime duration: 196ns, args: 
2022/07/05 08:59:58 TemplateCache duration: 331ns, args: 
2022/07/05 08:59:58 TemplateCache duration: 226ns, args: 
2022/07/05 08:59:58 Shell duration: 309ns, args: 
2022/07/05 08:59:58 debug: Pwd
/home/bendn
2022/07/05 08:59:58 Pwd duration: 3.058µs, args: 
2022/07/05 08:59:58 GOOS duration: 106ns, args: 
2022/07/05 08:59:58 ErrorCode duration: 269ns, args: 
2022/07/05 08:59:58 TemplateCache duration: 82ns, args: 
2022/07/05 08:59:58 TemplateCache duration: 228ns, args: 
2022/07/05 08:59:58 Shell duration: 247ns, args: 
2022/07/05 08:59:58 TemplateCache duration: 250ns, args: 
2022/07/05 08:59:58 Flags duration: 127ns, args: 
2022/07/05 08:59:58 debug: Pwd
/home/bendn
2022/07/05 08:59:58 Pwd duration: 3.84µs, args: 
2022/07/05 08:59:58 GOOS duration: 100ns, args: 
2022/07/05 08:59:58 Shell duration: 98ns, args: 
2022/07/05 08:59:58 Flags duration: 79ns, args: 
2022/07/05 08:59:58 TemplateCache duration: 107ns, args: 
2022/07/05 08:59:58 TemplateCache duration: 220ns, args: 
2022/07/05 08:59:58 Shell duration: 123ns, args: 
2022/07/05 08:59:58 debug: Pwd
/home/bendn
2022/07/05 08:59:58 Pwd duration: 3.863µs, args: 
2022/07/05 08:59:58 GOOS duration: 104ns, args: 
2022/07/05 08:59:58 HasCommand duration: 1.421µs, args: bash
2022/07/05 08:59:58 debug: RunCommand
08:59滛  (28.99°C) feels 34.5°C (c)
2022/07/05 08:59:58 RunCommand duration: 60.518711ms, args: bash -c weather
2022/07/05 08:59:58 RunShellCommand duration: 60.53432ms, args: bash weather
2022/07/05 08:59:58 TemplateCache duration: 456ns, args: 
2022/07/05 08:59:58 TemplateCache duration: 224ns, args: 
2022/07/05 08:59:58 Shell duration: 474ns, args: 
2022/07/05 08:59:58 debug: Getenv

2022/07/05 08:59:58 Getenv duration: 7.156µs, args: XDG_CACHE_HOME
2022/07/05 08:59:58 CachePath duration: 67.503µs, args: 
2022/07/05 08:59:58 Flags duration: 99ns, args: 
JanDeDobbeleer commented 2 years ago

@bend-n fish does say that command is valid (see the color). I'm using fish daily and the exit segment works, I'm wondering if this is how fish interprets things rather than being a bug.

bend-n commented 2 years ago

@JanDeDobbeleer image I think the color is just if its a valid path... How do you make the exit segment nonzero?

lewis-yeung commented 2 years ago

🪲 Bug confirmed. Related code:

https://github.com/JanDeDobbeleer/oh-my-posh/blob/65192cb065eba4e129e7bbea0d59f72987a73e14/src/shell/scripts/omp.fish#L8-L12

The error code will always be 0 since the previous command printf \e\[0J never fails. Easy to fix. I'll submit a PR.

JanDeDobbeleer commented 2 years ago

@lewis-yeung can't believe I missed that 🤦🏻

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