79349828

Date: 2025-01-12 11:46:19
Score: 1
Natty:
Report link

Resolved. Thank you @Compo for your observations. I discarded the .bat script approach. Final solution, I create an event in the .ps1 profile, that run every time a command (besides itself) runs, calculate the current window wide and save it in a global variable accessible from the omp.json theme file. Here is the code:

oh-my-posh init pwsh --config 'D:\repos\zsh-pwsh-wt\windows-pws-posh\kalimod.omp.json' | Invoke-Expression
$width = [console]::WindowWidth
    $result = "ˍ" * ($width-1)
    [System.Environment]::SetEnvironmentVariable("PROMPT_LINE", $result, [System.EnvironmentVariableTarget]::Process)
Register-EngineEvent -SourceIdentifier PowerShell.OnIdle -Action {
    $width = [console]::WindowWidth
    $result = "ˍ" * ($width-1)
    [System.Environment]::SetEnvironmentVariable("PROMPT_LINE", $result, [System.EnvironmentVariableTarget]::Process)
    oh-my-posh init pwsh --config 'D:\repos\zsh-pwsh-wt\windows-pws-posh\kalimod.omp.json' | Invoke-Expression
}

And here is the block and how I call it in the theme:

   {
  "type": "prompt",
  "alignment": "left",
  "segments": [
    {
      "type": "command",
      "style": "plain",
      "foreground": "#ffffff",
      "properties": {
        "shell": "powershell",
        "command": "$env:PROMPT_LINE"
      }
    }
  ]
},
Reasons:
  • Blacklisted phrase (0.5): Thank you
  • Long answer (-1):
  • Has code block (-0.5):
  • User mentioned (1): @Compo
  • Self-answer (0.5):
  • Low reputation (0.5):
Posted by: Laplace'sDemon