1

I cannot seem to get foreground_templates to work for a text segment. Below is the last block of my prompt.

If I am running with normal privileges, I should see just a green "crescent moon" prompt character. If I am running with elevated privileges, I should see a red pill with an "unlocked" icon, followed by a space, then a red crescent moon prompt character.

The {{ if .Root }} template in the text property to add the additional space works. The {{ if .Root }} template in the foreground_templates does not work. No matter what I try, I always get a green crescent moon.

I can work around it using template coloring in the text property, but it is quite a bit uglier:

"text": "{{ if .Root }} <lightRed>\uF5DA</>{{ else }}\uF5DA{{ end }}"

I can't spot anything wrong. Can you?

Environment:

  • Windows 10
  • Consoles tested (all render the same):
    • Windows Terminal 1.11.2921.0
    • Powershell 5.1
    • PowerShell 7.0.3
  • oh-my-posh 6.4.3
  • SauceCodePro Nerd Font

{
    "type": "prompt",
    "alignment": "left",
    "newline": true,
    "segments": [
        {
            "type": "root",
            "style": "diamond",
            "leading_diamond": "\uE0B6",
            "trailing_diamond": "\uE0B4",
            "foreground": "black",
            "background": "lightRed",
            "properties": {
                "root_icon": "\uF13E"
            }
        },
        {
            "type": "text",
            "style": "plain",
            "foreground": "lightGreen",
            "foreground_templates": [
                "{{ if .Root }}lightRed{{ end }}"
            ],
            "properties": {
                "prefix": "",
                "text": "{{ if .Root }} {{ end }}\uF5DA"
            }
        }
    ]
}
jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
spinard
  • 21
  • 3

0 Answers0