batch file - Command segment in .omp.json Oh-my-posh theme - Stack Overflow

时间: 2025-01-06 admin 业界

I've been modifying to my taste, the theme kali, from oh my posh.

I encountered the following problem.

I have this segment

{
  "type": "prompt",
  "alignment": "left",
  "segments": [
    {
      "type": "command",
      "style": "plain",
      "foreground": "#ffffff",
      "properties": {
        "shell": "cmd",
        "command": "cmd /C D:\\repos\\zsh-pwsh-wt\\windows-pws-posh\\center.bat"
      },
      "template": "{{ .Output }}"
    }
  ]
},

The point of that segment is to print a line as wide as the window above the main prompt. I do it through cmd because of compatibility issues with pwsh.

The file center.bat works perfectly by its own, prints the line as it should. The problem is that when I call that script file, the line it prints is shorter than the window width.

Here are examples:

  • Running the script directly:

  • Adding the segment/block:

Also, this example scenario:

  • When I run center.bat by itself the width is 172.
  • When it's run from omp.json, it is 120.

Checking again, it always returns 120 when it runs from the template, despite the window size.

  • Template:
> {
  "$schema": ".json",
  "blocks": [

    {
      "type": "prompt",
      "alignment": "right",
      "segments": [
        {
          "type": "command",
          "style": "plain",
          "foreground": "#ffffff",
          "properties": {
            "shell": "cmd",
            "command": "cmd /C D:\\repos\\zsh-pwsh-wt\\windows-pws-posh\\center.bat"
          },
          "template": "{{ .Output }}"
        }
      ]
    },
    

    {
      "alignment": "left",
      "segments": [
        {

          "properties": { "display_host": true },
          "style": "plain",
          "template": "\n<#ffffff>\u250c\u2500\u2500(</#ffffff><#00FF00>{{ .UserName }}</#00FF00>