JanDeDobbeleer / oh-my-posh

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

Theme file overwritten on start, errors out with "unable to create text based on template" #1815

Closed Ifiht closed 2 years ago

Ifiht commented 2 years ago

Code of Conduct

What happened?

I've narrowed it down to the oh-my-posh init command. After running the following: oh-my-posh --init --shell pwsh --config ~/stelbent.minimal-mod.omp.json | Invoke-Expression My original stelbent.minimal-mod.omp.json is moved to stelbent.minimal-mod.omp.json.bak, a new stelbent.minimal-mod.omp.json is created with different contents, and my prompt changes to the below:

                                                                                     pwsh | 10:37:54
unable to create text based on template(base 3.8.12)  ~ 
└$

What's going wrong here? I've used oh-my-posh on other systems before, without this behavior.

Theme

stelbent.minimal-mod.omp.json (replaced)

{
  "$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json",
  "blocks": [
    {
      "alignment": "right",
      "segments": [
        {
          "foreground": "#007acc",
          "properties": {
            "template": "{{ .Name }}"
          },
          "style": "plain",
          "type": "shell"
        },
        {
          "foreground": "#ff8080",
          "properties": {
            "root_icon": "root",
            "template": " <#757575,>as</> \uf0e7"
          },
          "style": "plain",
          "type": "root"
        },
        {
          "foreground": "#689f38",
          "properties": {
            "template": " <#757575,>|</> {{ .CurrentDate | date .Format }}",
            "time_format": "15:04:05"
          },
          "style": "plain",
          "type": "time"
        }
      ],
      "type": "prompt"
    },
    {
      "alignment": "left",
      "newline": true,
      "segments": [
        {
          "foreground": "#757575",
          "properties": {
            "template": "\u250c {{ .UserName }}@{{ .ComputerName }} "
          },
          "style": "plain",
          "type": "session"
        },
        {
          "foreground": "#C9C9C9",
          "properties": {
            "template": "({{ if .Error }}{{ .Error }}{{ else }}{{ if .Venv }}{{ .Venv }} {{ end }}{{ .Full }}{{ end }}) "
          },
          "style": "plain",
          "type": "python"
        },
        {
          "background": "#91ddff",
          "foreground": "#100e23",
          "powerline_symbol": "\ue0b0",
          "properties": {
            "style": "folder",
            "template": " {{ .Path }} "
          },
          "style": "powerline",
          "type": "path"
        },
        {
          "background": "#95ffa4",
          "background_templates": [
            "{{ if or (.Working.Changed) (.Staging.Changed) }}#ff9248{{ end }}",
            "{{ if and (gt .Ahead 0) (gt .Behind 0) }}#f26d50{{ end }}",
            "{{ if gt .Ahead 0 }}#89d1dc{{ end }}",
            "{{ if gt .Behind 0 }}#c5b6ad{{ end }}"
          ],
          "foreground": "#100e23",
          "powerline_symbol": "\ue0b0",
          "properties": {
            "branch_ahead_icon": "\u2191",
            "branch_behind_icon": "\u2193",
            "branch_gone": "\u2262",
            "branch_icon": "\ue0a0 ",
            "branch_identical_icon": "\u2261",
            "cherry_pick_icon": "\u2713 ",
            "commit_icon": "\u25b7 ",
            "fetch_stash_count": true,
            "fetch_status": true,
            "merge_icon": "\u25f4 ",
            "no_commits_icon": "[no commits]",
            "rebase_icon": "\u2c62 ",
            "tag_icon": "\u25b6 ",
            "template": " {{ .HEAD }}{{ .BranchStatus }}{{ if .Working.Changed }} {{ .Working.String }}{{ end }}{{ if and (.Working.Changed) (.Staging.Changed) }} \u2502{{ end }}{{ if .Staging.Changed }} {{ .Staging.String }}{{ end }}{{ if gt .StashCount 0 }} {{ .StashCount }}{{ end }} "
          },
          "style": "powerline",
          "type": "git"
        },
        {
          "background": "#ffee58",
          "foreground": "#100e23",
          "powerline_symbol": "\ue0b0",
          "properties": {
            "template": " {{ .WorkspaceName }}{{ if .Version }} {{ .Version }}{{ end }} "
          },
          "style": "powerline",
          "type": "terraform"
        },
        {
          "background": "#ff8080",
          "foreground": "#ffffff",
          "powerline_symbol": "\ue0b0",
          "properties": {
            "template": " error "
          },
          "style": "powerline",
          "type": "exit"
        }
      ],
      "type": "prompt"
    },
    {
      "alignment": "left",
      "newline": true,
      "segments": [
        {
          "foreground": "#757575",
          "properties": {
            "template": "\u2514"
          },
          "style": "plain",
          "type": "text"
        },
        {
          "foreground": "#ffffff",
          "properties": {
            "template": "$"
          },
          "style": "plain",
          "type": "text"
        }
      ],
      "type": "prompt"
    }
  ],
  "final_space": true,
  "osc99": true,
  "version": 1
}

stelbent.minimal-mod.omp.json.bak (original)

{
  "$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json",
  "osc99": true,
  "blocks": [
    {
      "type": "prompt",
      "alignment": "right",
      "segments": [
        {
          "type": "shell",
          "style": "plain",
          "foreground": "#007acc",
          "properties": {
            "prefix": "",
            "postfix": ""
          }
        },
        {
          "type": "root",
          "style": "plain",
          "foreground": "#ff8080",
          "properties": {
            "prefix": " <#757575,>as</> ",
            "postfix": "",
            "root_icon": "root"
          }
        },
        {
          "type": "time",
          "style": "plain",
          "foreground": "#689f38",
          "properties": {
            "prefix": " <#757575,>|</> ",
            "postfix": "",
            "time_format": "15:04:05"
          }
        }
      ]
    },
    {
      "type": "prompt",
      "alignment": "left",
      "newline": true,
      "segments": [
        {
          "type": "session",
          "style": "plain",
          "foreground": "#757575",
          "properties": {
            "prefix": "\u250c ",
            "template": "{{ .UserName }}@{{ .ComputerName }}"
          }
        },
        {
          "type": "python",
          "style": "plain",
          "foreground": "#C9C9C9",
          "properties": {
            "prefix": "(",
            "postfix": ") "
          }
        },
        {
          "type": "path",
          "style": "powerline",
          "powerline_symbol": "\ue0b0",
          "foreground": "#100e23",
          "background": "#91ddff",
          "properties": {
            "style": "folder",
            "enable_hyperlink": false
          }
        },
        {
          "type": "git",
          "style": "powerline",
          "powerline_symbol": "\ue0b0",
          "foreground": "#100e23",
          "background": "#95ffa4",
          "background_templates": [
            "{{ if or (.Working.Changed) (.Staging.Changed) }}#ff9248{{ end }}",
            "{{ if and (gt .Ahead 0) (gt .Behind 0) }}#f26d50{{ end }}",
            "{{ if gt .Ahead 0 }}#89d1dc{{ end }}",
            "{{ if gt .Behind 0 }}#c5b6ad{{ end }}"
          ],
          "properties": {
            "fetch_status": true,
            "fetch_stash_count": true,
            "branch_ahead_icon": "\u2191",
            "branch_behind_icon": "\u2193",
            "branch_gone": "\u2262",
            "branch_icon": "\ue0a0 ",
            "branch_identical_icon": "\u2261",
            "cherry_pick_icon": "\u2713 ",
            "commit_icon": "\u25b7 ",
            "merge_icon": "\u25f4 ",
            "no_commits_icon": "[no commits]",
            "rebase_icon": "\u2c62 ",
            "tag_icon": "\u25b6 ",
            "template": "{{ .HEAD }}{{ .BranchStatus }}{{ if .Working.Changed }} {{ .Working.String }}{{ end }}{{ if and (.Working.Changed) (.Staging.Changed) }} \u2502{{ end }}{{ if .Staging.Changed }} {{ .Staging.String }}{{ end }}{{ if gt .StashCount 0 }} {{ .StashCount }}{{ end }}"
          }
        },
        {
          "type": "terraform",
          "style": "powerline",
          "powerline_symbol": "\ue0b0",
          "foreground": "#100e23",
          "background": "#ffee58"
        },
        {
          "type": "exit",
          "style": "powerline",
          "powerline_symbol": "\ue0b0",
          "foreground": "#ffffff",
          "background": "#ff8080",
          "properties": {
            "template": "error"
          }
        }
      ]
    },
    {
      "type": "prompt",
      "alignment": "left",
      "newline": true,
      "segments": [
        {
          "type": "text",
          "style": "plain",
          "foreground": "#757575",
          "properties": {
            "prefix": "",
            "postfix": "",
            "text": "\u2514 "
          }
        },
        {
          "type": "text",
          "style": "plain",
          "foreground": "#ffffff",
          "properties": {
            "prefix": "",
            "postfix": "",
            "text": "$"
          }
        }
      ]
    }
  ],
  "final_space": true
}

What OS are you seeing the problem on?

Windows

Which shell are you using?

powershell

Log output

└$ Write-PoshDebug

Version: 7.25.0

Segments:

ConsoleTitle(false) -   0 ms -
shell(true)      -   1 ms - pwsh
root(false)      -   0 ms -
time(true)       -   0 ms -  | 10:49:06
session(true)    -   0 ms - unable to create text based on template
python(true)     - 413 ms - (base 3.8.12)
path(true)       -   0 ms -  ~
git(false)       -  25 ms -
terraform(false) -  23 ms -
exit(true)       -   2 ms -  error
text(true)       -   0 ms - └
text(true)       -   0 ms - $

Run duration: 469.0088ms

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

Logs:

2022/02/26 10:49:06 Args duration: 0s, args:
2022/02/26 10:49:06 Args duration: 0s, args:
2022/02/26 10:49:06 Args duration: 0s, args:
2022/02/26 10:49:06 Shell duration: 18.1095ms, args:
2022/02/26 10:49:06 debug: Getenv

2022/02/26 10:49:06 Getenv duration: 0s, args: OMP_CACHE_DISABLED
2022/02/26 10:49:06 debug: Pwd
C:\Users\ifiht
2022/02/26 10:49:06 Pwd duration: 0s, args:
2022/02/26 10:49:06 debug: Home
C:\Users\ifiht
2022/02/26 10:49:06 PathSeparator duration: 0s, args:
2022/02/26 10:49:06 PathSeparator duration: 0s, args:
2022/02/26 10:49:06 debug: Pwd
C:\Users\ifiht
2022/02/26 10:49:06 Pwd duration: 0s, args:
2022/02/26 10:49:06 debug: Home
C:\Users\ifiht
2022/02/26 10:49:06 Shell duration: 0s, args:
2022/02/26 10:49:06 Root duration: 449µs, args:
2022/02/26 10:49:06 Shell duration: 0s, args:
2022/02/26 10:49:06 ErrorCode duration: 0s, args:
2022/02/26 10:49:06 IsWsl duration: 0s, args:
2022/02/26 10:49:06 debug: Pwd
C:\Users\ifiht
2022/02/26 10:49:06 Pwd duration: 0s, args:
2022/02/26 10:49:06 debug: Home
C:\Users\ifiht
2022/02/26 10:49:06 PathSeparator duration: 0s, args:
2022/02/26 10:49:06 PathSeparator duration: 0s, args:
2022/02/26 10:49:06 User duration: 0s, args:
2022/02/26 10:49:06 Host duration: 0s, args:
2022/02/26 10:49:06 GOOS duration: 0s, args:
2022/02/26 10:49:06 TemplateCache duration: 449µs, args:
2022/02/26 10:49:06 debug: Pwd
C:\Users\ifiht
2022/02/26 10:49:06 Pwd duration: 0s, args:
2022/02/26 10:49:06 debug: Home
C:\Users\ifiht
2022/02/26 10:49:06 Root duration: 0s, args:
2022/02/26 10:49:06 debug: Pwd
C:\Users\ifiht
2022/02/26 10:49:06 Pwd duration: 0s, args:
2022/02/26 10:49:06 debug: Home
C:\Users\ifiht
2022/02/26 10:49:06 TemplateCache duration: 0s, args:
2022/02/26 10:49:06 debug: Pwd
C:\Users\ifiht
2022/02/26 10:49:06 Pwd duration: 0s, args:
2022/02/26 10:49:06 debug: Home
C:\Users\ifiht
2022/02/26 10:49:06 debug: Getenv

2022/02/26 10:49:06 Getenv duration: 0s, args: SSH_CONNECTION
2022/02/26 10:49:06 debug: Getenv

2022/02/26 10:49:06 Getenv duration: 0s, args: SSH_CLIENT
2022/02/26 10:49:06 TemplateCache duration: 0s, args:
2022/02/26 10:49:06 debug: Pwd
C:\Users\ifiht
2022/02/26 10:49:06 Pwd duration: 0s, args:
2022/02/26 10:49:06 debug: Home
C:\Users\ifiht
2022/02/26 10:49:06 debug: Pwd
C:\Users\ifiht
2022/02/26 10:49:06 Pwd duration: 0s, args:
2022/02/26 10:49:06 debug: Home
C:\Users\ifiht
2022/02/26 10:49:06 debug: Getenv

2022/02/26 10:49:06 Getenv duration: 0s, args: VIRTUAL_ENV
2022/02/26 10:49:06 debug: Getenv

2022/02/26 10:49:06 Getenv duration: 0s, args: CONDA_ENV_PATH
2022/02/26 10:49:06 debug: Getenv
base
2022/02/26 10:49:06 Getenv duration: 0s, args: CONDA_DEFAULT_ENV
2022/02/26 10:49:06 PathSeparator duration: 0s, args:
2022/02/26 10:49:06 PathSeparator duration: 0s, args:
2022/02/26 10:49:06 PathSeparator duration: 0s, args:
2022/02/26 10:49:06 PathSeparator duration: 0s, args:
2022/02/26 10:49:06 PathSeparator duration: 0s, args:
2022/02/26 10:49:06 HasCommand duration: 1.7182ms, args: python
2022/02/26 10:49:06 debug: RunCommand
Python 3.8.12
2022/02/26 10:49:06 RunCommand duration: 409.982ms, args: python --version
2022/02/26 10:49:06 TemplateCache duration: 0s, args:
2022/02/26 10:49:06 TemplateCache duration: 0s, args:
2022/02/26 10:49:06 debug: Pwd
C:\Users\ifiht
2022/02/26 10:49:06 Pwd duration: 0s, args:
2022/02/26 10:49:06 debug: Home
C:\Users\ifiht
2022/02/26 10:49:06 debug: Pwd
C:\Users\ifiht
2022/02/26 10:49:06 Pwd duration: 0s, args:
2022/02/26 10:49:06 Args duration: 0s, args:
2022/02/26 10:49:06 debug: Home
C:\Users\ifiht
2022/02/26 10:49:06 GOOS duration: 0s, args:
2022/02/26 10:49:06 GOOS duration: 0s, args:
2022/02/26 10:49:06 PathSeparator duration: 0s, args:
2022/02/26 10:49:06 PathSeparator duration: 0s, args:
2022/02/26 10:49:06 PathSeparator duration: 0s, args:
2022/02/26 10:49:06 GOOS duration: 0s, args:
2022/02/26 10:49:06 IsWsl duration: 0s, args:
2022/02/26 10:49:06 StackCount duration: 0s, args:
2022/02/26 10:49:06 TemplateCache duration: 0s, args:
2022/02/26 10:49:06 debug: Pwd
C:\Users\ifiht
2022/02/26 10:49:06 Pwd duration: 0s, args:
2022/02/26 10:49:06 debug: Home
C:\Users\ifiht
2022/02/26 10:49:06 GOOS duration: 0s, args:
2022/02/26 10:49:06 HasCommand duration: 24.7775ms, args: git.exe
2022/02/26 10:49:06 debug: Pwd
C:\Users\ifiht
2022/02/26 10:49:06 Pwd duration: 0s, args:
2022/02/26 10:49:06 error: HasParentFilePath
CreateFile C:\.git: The system cannot find the file specified.
2022/02/26 10:49:06 HasParentFilePath duration: 1.0123ms, args: .git
2022/02/26 10:49:06 debug: Pwd
C:\Users\ifiht
2022/02/26 10:49:06 Pwd duration: 0s, args:
2022/02/26 10:49:06 debug: Home
C:\Users\ifiht
2022/02/26 10:49:06 debug: Pwd
C:\Users\ifiht
2022/02/26 10:49:06 Pwd duration: 0s, args:
2022/02/26 10:49:06 HasFolder duration: 0s, args: C:\Users\ifiht\.terraform
2022/02/26 10:49:06 debug: Getenv
C:\Users\ifiht\AppData\Local
2022/02/26 10:49:06 Getenv duration: 0s, args: LOCALAPPDATA
2022/02/26 10:49:06 PathSeparator duration: 0s, args:
2022/02/26 10:49:06 HasFilesInDir duration: 0s, args: terraform.exe
2022/02/26 10:49:06 error: HasCommand
no Windows Store App
2022/02/26 10:49:06 HasCommand duration: 23.5212ms, args: terraform
2022/02/26 10:49:06 debug: Pwd
C:\Users\ifiht
2022/02/26 10:49:06 Pwd duration: 0s, args:
2022/02/26 10:49:06 debug: Home
C:\Users\ifiht
2022/02/26 10:49:06 ErrorCode duration: 0s, args:
2022/02/26 10:49:06 ErrorCode duration: 0s, args:
2022/02/26 10:49:06 TemplateCache duration: 0s, args:
2022/02/26 10:49:06 debug: Pwd
C:\Users\ifiht
2022/02/26 10:49:06 Pwd duration: 0s, args:
2022/02/26 10:49:06 debug: Home
C:\Users\ifiht
2022/02/26 10:49:06 TemplateCache duration: 0s, args:
2022/02/26 10:49:06 debug: Pwd
C:\Users\ifiht
2022/02/26 10:49:06 Pwd duration: 0s, args:
2022/02/26 10:49:06 debug: Home
C:\Users\ifiht
2022/02/26 10:49:06 TemplateCache duration: 0s, args:
2022/02/26 10:49:06 debug: Getenv
C:\Users\ifiht\AppData\Local
2022/02/26 10:49:06 Getenv duration: 0s, args: LOCALAPPDATA
2022/02/26 10:49:06 CachePath duration: 0s, args:
JanDeDobbeleer commented 2 years ago

@Ifiht we needed to migrate the configurations (1 time) to have support for templates without people needing to do a manual fix. In this case one element wasn't migrated correctly. In the session segment, change .ComputerName to .HostName.

Ifiht commented 2 years ago

@JanDeDobbeleer got it - confirmed the fix. Thanks for the help, couldn't find that info anywhere!

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