JanDeDobbeleer / oh-my-posh

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

[Command] conditional commands - as described in the documentation - don't work #1783

Closed thorstenkampe closed 2 years ago

thorstenkampe commented 2 years ago

Code of Conduct

What happened?

According to the documentation the segment below should output a pretty printed date when the current directory is a git repository and a standard date via date otherwise. This works as expected in a git repository but not when not in a repository (the git error (fatal: not a git repository (or any of the parent directories): .git) is shown instead).

Theme

directly from the documentation

{
    "$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json",
    "version": 1,
    "blocks": [
        {
            "type": "prompt",
            "alignment": "right",
            "segments": [
                {
                    "type": "command",
                    "style": "plain",
                    "properties": {
                        "shell": "bash",
                        "command": "git log --pretty=format:%cr -1 || date +%H:%m:%S"
                    }
                }
            ]
        }
    ]
}

What OS are you seeing the problem on?

Windows, Linux

Which shell are you using?

powershell

Log output

Version: 7.19.1

Segments:

ConsoleTitle(false) -   0 ms - ]0;tmp
command(true)  -  36 ms -  fatal: not a git repository (or any of the parent directories): .git
 

Run duration: 36.527554ms

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

Logs:

2022/02/19 13:26:28 Args duration: 111ns, args: 
2022/02/19 13:26:28 Args duration: 49ns, args: 
2022/02/19 13:26:28 Args duration: 125ns, args: 
2022/02/19 13:26:28 Shell duration: 547.618µs, args: 
2022/02/19 13:26:28 debug: Getenv

2022/02/19 13:26:28 Getenv duration: 9.961µs, args: OMP_CACHE_DISABLED
2022/02/19 13:26:28 debug: Pwd
/home/thorsten/tmp
2022/02/19 13:26:28 Pwd duration: 22.371µs, args: 
2022/02/19 13:26:28 PathSeperator duration: 56ns, args: 
2022/02/19 13:26:28 PathSeperator duration: 31ns, args: 
2022/02/19 13:26:28 PathSeperator duration: 50ns, args: 
2022/02/19 13:26:28 PathSeperator duration: 30ns, args: 
2022/02/19 13:26:28 PathSeperator duration: 31ns, args: 
2022/02/19 13:26:28 debug: Pwd
/home/thorsten/tmp
2022/02/19 13:26:28 Pwd duration: 1.639µs, args: 
2022/02/19 13:26:28 HasCommand duration: 21.171µs, args: bash
2022/02/19 13:26:28 error: RunCommand
cmd.Start() failed with 'fatal: not a git repository (or any of the parent directories): .git
'
2022/02/19 13:26:28 RunCommand duration: 35.262752ms, args: bash -c git log --pretty=format:%cr -1
2022/02/19 13:26:28 RunShellCommand duration: 35.286325ms, args: bash git log --pretty=format:%cr -1
2022/02/19 13:26:28 Root duration: 1.575µs, args: 
2022/02/19 13:26:28 Shell duration: 816ns, args: 
2022/02/19 13:26:28 ErrorCode duration: 307ns, args: 
2022/02/19 13:26:28 debug: Getenv

2022/02/19 13:26:28 Getenv duration: 4.674µs, args: WSL_DISTRO_NAME
2022/02/19 13:26:28 IsWsl duration: 12.77µs, args: 
2022/02/19 13:26:28 debug: Pwd
/home/thorsten/tmp
2022/02/19 13:26:28 Pwd duration: 3.735µs, args: 
2022/02/19 13:26:28 PathSeperator duration: 118ns, args: 
2022/02/19 13:26:28 PathSeperator duration: 66ns, args: 
2022/02/19 13:26:28 PathSeperator duration: 67ns, args: 
2022/02/19 13:26:28 PathSeperator duration: 108ns, args: 
2022/02/19 13:26:28 PathSeperator duration: 65ns, args: 
2022/02/19 13:26:28 User duration: 897ns, args: 
2022/02/19 13:26:28 Host duration: 2.951µs, args: 
2022/02/19 13:26:28 GOOS duration: 103ns, args: 
2022/02/19 13:26:28 TemplateCache duration: 129.925µs, args: 
2022/02/19 13:26:28 debug: Getenv

2022/02/19 13:26:28 Getenv duration: 2.284µs, args: XDG_CACHE_HOME
2022/02/19 13:26:28 CachePath duration: 23.612µs, args:
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.