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

Error: unknown command "posh-prompt.json" for "oh-my-posh" #1940

Closed mdnava closed 2 years ago

mdnava commented 2 years ago

Code of Conduct

What happened?

The OhMyPosh prompt stopped working on Cmd after v7.37.0 .. But works fine on Pwsh, Bash and Fish.

The last version I'm able to use it is v7.37.0 .. I've tried every version after that (up to v7.41.0) in case the issue was fixed, but the only way I can seem to be able to use it with Cmd is to rollback to the older version.

2022-03-17 21 24 34

This is the Clink injection in the Cmd Autorun file:

%Utilities%\Clink\Clink\clink_x64.exe inject --quiet --nolog

This is the LUA code that starts the prompt..

local ohmyposh_prompt = clink.promptfilter(1)
function ohmyposh_prompt:filter(prompt)
    prompt = io.popen(os.getenv("Utilities").."\\OhMyPosh\\oh-my-posh.exe -config "..os.getenv("EnvScripts").."\\AutoRun\\posh-prompt.json"):read("*a")
    return prompt, false
end

——————————————— Also, please check comment on issue https://github.com/JanDeDobbeleer/oh-my-posh/issues/1907#issuecomment-1065973832 related to Zsh.. OhMyPosh is adding up something to the beginning of every prompt in Zsh. In my case it was the "%" character, and in your test it seems it was the "zsh>" string.

Theme

{
  "$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json",
  "version": 1,
  "blocks": [

    // =====================
    // Prompt: First Line
    // =====================

    {
          "type": "prompt",
          "alignment": "left",
          "segments": [
        {
          "type": "text",
          "style": "plain",
          "properties": {
              "template": "{{if .Env.PROMPT_PRE_LNBR}}\n{{end}}"
          }
        },
        {
          "type": "text",
          "style": "plain",
          "background": "#FF00FF",
          "foreground": "#ffffff",
          "properties": {
            "template": " {{if .Env.WSYSTEM}}{{.Env.WSYSTEM}}{{end}}{{if .Env.MSYSTEM}}{{.Env.MSYSTEM}}{{end}}{{if .Root}}\uf997{{end}}{{if not .Root}} {{end}}"
          }
        },
        {
          "type": "path",
          "style": "diamond",
          "background": "#FFE50A",
          "foreground": "#000000",
          "trailing_diamond": "<#FFE50A, #008000>\ue0b0</>",
          "leading_diamond": "<#FF00FF, #FFE50A>\ue0b0</>",
          "powerline_symbol": "\ue0b0",
          "properties": {
            "home_icon": "\ue617",
            "mapped_locations": {
              "C:\\Program Files": "$PROGRAMFILES",
              "C:\\Program Files (x86)": "$PROGRAMFILES32",
              "C:\\Users": "\uf007",
              "C:\\Windows": "\ue70f",
              "D:\\USERNAME": "\ue617",
              "D:\\USERNAME\\Dropbox": "\uf16b",
              "D:\\USERNAME\\Google Drive": "\ue731",
              "D:\\USERNAME\\OneDrive": "\ue762",
              "D:\\USERNAME\\OneDrive\\Images\\": "\uf1c5\\",
              "D:\\USERNAME\\OneDrive\\Music\\": "\uf001\\"
            },
            "stack_count_enabled:": true,
            "style": "full",
            "template": " {{ .Path }} "
          }
        },
        {
          "type": "time",
          "style": "diamond",
          "trailing_diamond": "\ue0b4",
          "background": "#008000",
          "foreground": "#FFFFFF",
          "properties": {
            "template": " {{ .CurrentDate | date .Format }} ",
            "time_format": "15:04:05"
          }
        },
        {   // Line ending space (Alt+255) to fix prompt mess after window resizing
            "type": "text",
            "style": "plain",
            "properties": { "text": " " }
        }
      ]
    },

    // =====================
    // Prompt: Second Line
    // =====================

    {
          "alignment": "left",
          "newline": true,
          "type": "prompt",
          "segments": [
          {
            "type": "git",
            "style": "diamond",
            "trailing_diamond": "\ue0bc",
            "background": "#95ffa4",
            "foreground": "#193549",
            "properties": {
              "branch_icon": "\ue0a0",
              "fetch_stash_count": true,
              "fetch_status": true,
              "fetch_upstream_icon": true,
              "template": " {{ .HEAD }}{{ .BranchStatus }}{{ if .Working.Changed }} \uf044 {{ .Working.String }}{{ end }}{{ if and (.Staging.Changed) (.Working.Changed) }} |{{ end }}{{ if .Staging.Changed }} \uf046 {{ .Staging.String }}{{ end }}{{ if gt .StashCount 0}} \uf692 {{ .StashCount }}{{ end }}{{ if gt .WorktreeCount 0}} \uf1bb {{ .WorktreeCount }}{{ end }} "
          }
        },
        {
          "type": "text",
          "style": "plain",
          "properties": {
          "template": "ϟ "
          }          
        }
      ]
    }
  ]
}

What OS are you seeing the problem on?

Windows

Which shell are you using?

zsh, bash, fish, powershell, other (please specify)

Log output

Error: unknown command "D:\\USERNAME\\OneDrive\\Command\\EnvScripts\\AutoRun\\posh-prompt.json" for "oh-my-posh"
Run 'oh-my-posh --help' for usage.
unknown command "D:\\USERNAME\\OneDrive\\Command\\EnvScripts\\AutoRun\\posh-prompt.json" for "oh-my-posh"

oh-my-posh prompt debug

Version: 7.41.0

Segments:

ConsoleTitle(false) - 189 ms -
session(true)  -  56 ms -  SYSTEM@TESLA 
path(true)     -  55 ms -  Desktop
shell(true)    -   0 ms -  oh-my-posh
text(true)     -   0 ms -  no config
exit(true)     -  32 ms -  

Run duration: 334.3109ms

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

Logs:

2022/03/17 21:19:06 Flags duration: 0s, args:
2022/03/17 21:19:06 Flags duration: 0s, args:
2022/03/17 21:19:06 debug: Getenv

2022/03/17 21:19:06 Getenv duration: 0s, args: OMP_CACHE_DISABLED
2022/03/17 21:19:06 Root duration: 997.5µs, args:
2022/03/17 21:19:06 Shell duration: 17.002ms, args:
2022/03/17 21:19:06 ErrorCode duration: 0s, args:
2022/03/17 21:19:06 IsWsl duration: 0s, args:
2022/03/17 21:19:06 debug: Pwd
D:\USERNAME\Desktop
2022/03/17 21:19:06 Pwd duration: 0s, args:
2022/03/17 21:19:06 debug: Home
D:\USERNAME
2022/03/17 21:19:06 PathSeparator duration: 0s, args:
2022/03/17 21:19:06 PathSeparator duration: 0s, args:
2022/03/17 21:19:06 PathSeparator duration: 0s, args:
2022/03/17 21:19:06 PathSeparator duration: 0s, args:
2022/03/17 21:19:06 PathSeparator duration: 0s, args:
2022/03/17 21:19:06 PathSeparator duration: 0s, args:
2022/03/17 21:19:06 PathSeparator duration: 0s, args:
2022/03/17 21:19:06 PathSeparator duration: 0s, args:
2022/03/17 21:19:06 PathSeparator duration: 0s, args:
2022/03/17 21:19:06 User duration: 0s, args:
2022/03/17 21:19:06 Host duration: 999.4µs, args:
2022/03/17 21:19:06 GOOS duration: 0s, args:
2022/03/17 21:19:06 TemplateCache duration: 18.9989ms, args:
2022/03/17 21:19:06 debug: Pwd
D:\USERNAME\Desktop
2022/03/17 21:19:06 Pwd duration: 0s, args:
2022/03/17 21:19:06 debug: Home
D:\USERNAME
2022/03/17 21:19:06 debug: Getenv

2022/03/17 21:19:06 Getenv duration: 0s, args: SSH_CONNECTION
2022/03/17 21:19:06 debug: Getenv

2022/03/17 21:19:06 Getenv duration: 0s, args: SSH_CLIENT
2022/03/17 21:19:06 TemplateCache duration: 0s, args:
2022/03/17 21:19:06 debug: Pwd
D:\USERNAME\Desktop
2022/03/17 21:19:06 Pwd duration: 0s, args:
2022/03/17 21:19:06 debug: Home
D:\USERNAME
2022/03/17 21:19:06 debug: Pwd
D:\USERNAME\Desktop
2022/03/17 21:19:06 Pwd duration: 0s, args:
2022/03/17 21:19:06 Flags duration: 0s, args:
2022/03/17 21:19:06 debug: Pwd
D:\USERNAME\Desktop
2022/03/17 21:19:06 Pwd duration: 0s, args:
2022/03/17 21:19:06 debug: Home
D:\USERNAME
2022/03/17 21:19:06 GOOS duration: 0s, args:
2022/03/17 21:19:06 GOOS duration: 0s, args:
2022/03/17 21:19:06 PathSeparator duration: 0s, args:
2022/03/17 21:19:06 PathSeparator duration: 0s, args:
2022/03/17 21:19:06 PathSeparator duration: 0s, args:
2022/03/17 21:19:06 PathSeparator duration: 0s, args:
2022/03/17 21:19:06 PathSeparator duration: 0s, args:
2022/03/17 21:19:06 PathSeparator duration: 0s, args:
2022/03/17 21:19:06 PathSeparator duration: 0s, args:
2022/03/17 21:19:06 PathSeparator duration: 0s, args:
2022/03/17 21:19:06 PathSeparator duration: 0s, args:
2022/03/17 21:19:06 PathSeparator duration: 0s, args:
2022/03/17 21:19:06 GOOS duration: 0s, args:
2022/03/17 21:19:06 IsWsl duration: 0s, args:
2022/03/17 21:19:06 StackCount duration: 0s, args:
2022/03/17 21:19:06 TemplateCache duration: 0s, args:
2022/03/17 21:19:06 debug: Pwd
D:\USERNAME\Desktop
2022/03/17 21:19:06 Pwd duration: 0s, args:
2022/03/17 21:19:06 debug: Home
D:\USERNAME
2022/03/17 21:19:06 Shell duration: 0s, args:
2022/03/17 21:19:06 TemplateCache duration: 0s, args:
2022/03/17 21:19:06 debug: Pwd
D:\USERNAME\Desktop
2022/03/17 21:19:06 Pwd duration: 0s, args:
2022/03/17 21:19:06 debug: Home
D:\USERNAME
2022/03/17 21:19:06 TemplateCache duration: 0s, args:
2022/03/17 21:19:06 debug: Pwd
D:\USERNAME\Desktop
2022/03/17 21:19:06 Pwd duration: 0s, args:
2022/03/17 21:19:06 debug: Home
D:\USERNAME
2022/03/17 21:19:06 ErrorCode duration: 0s, args:
2022/03/17 21:19:06 TemplateCache duration: 0s, args:
2022/03/17 21:19:06 TemplateCache duration: 0s, args:
2022/03/17 21:19:06 debug: Getenv
C:\Users\USERNAME\AppData\Local
2022/03/17 21:19:06 Getenv duration: 0s, args: LOCALAPPDATA
2022/03/17 21:19:06 CachePath duration: 0s, args:

Error: unknown command "D:\\USERNAME\\OneDrive\\Command\\EnvScripts\\AutoRun\\posh-prompt.json" for "oh-my-posh"
Run 'oh-my-posh --help' for usage.
unknown command "D:\\USERNAME\\OneDrive\\Command\\EnvScripts\\AutoRun\\posh-prompt.json" for "oh-my-posh"
JanDeDobbeleer commented 2 years ago

@mdnava please follow the official guide to initialize oh-my-posh in cmd as this way changes to the CLI will always break your prompt.

mdnava commented 2 years ago

I tried this:

load(io.popen("oh-my-posh.exe prompt init cmd -config D:/mdnava/OneDrive/Command/EnvScripts/AutoRun/posh-prompt.json"):read("*a"))()

But got this:

Error: invalid argument "D:/mdnava/OneDrive/Command/EnvScripts/AutoRun/posh-prompt.json" for "oh-my-posh prompt init"

I tried this:

load(io.popen("oh-my-posh.exe prompt init cmd -config "..os.getenv("EnvScripts").."\\AutoRun\\posh-prompt.json"):read("*a"))()

But got this:

Error: invalid argument "D:\\mdnava\\OneDrive\\Command\\EnvScripts\\AutoRun\\posh-prompt.json" for "oh-my-posh prompt init"

What am I doing wrong with the args ?

JanDeDobbeleer commented 2 years ago

@mdnava you need to use --config.

load(io.popen('oh-my-posh prompt init cmd --config="..os.getenv("EnvScripts").."\\AutoRun\\posh-prompt.json"'):read("*a"))()
mdnava commented 2 years ago

Nevermind, is working now.. I had been using -config instead of --config for quite some time. I suppose it stopped working after v7.37 ..

Thank you!

JanDeDobbeleer commented 2 years ago

@mdnava the previous CLI implementation allowed the use of -config, that's now no longer possible. You can use -c now though.

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.