Oh-my-posh3: Unrecognized commands cause the theme to not work

Created on 26 Nov 2020  ·  16Comments  ·  Source: JanDeDobbeleer/oh-my-posh3

Prerequisites

  • [x] I have read and understand the CONTRIBUTING guide
  • [x] I looked for duplicate issues before submitting this one

Description

Unrecognized commands cause the theme to not work

Environment

  • Oh my Posh version: 3.44.1
  • Theme: material
  • Operating System: Windows 10
  • Shell: Powershell
  • Terminal: Windows Terminal

Steps to Reproduce

❯❯  anvo  15:05  unknown
unknown: The term 'unknown' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

Expected behavior: [What you expected to happen]

❯❯  anvo  15:05  unknown
unknown: The term 'unknown' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
❯❯  anvo  15:06  # correct

Actual behavior: [What actually happened]

❯❯  anvo  15:05  unknown
unknown: The term 'unknown' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
PS> # incorrect
powershell

Most helpful comment

The reason is that $global:LASTEXITCODE can be empty. This fixes it:

[ScriptBlock]$Prompt = {
    $lastCommandSuccess = $?
    $realLASTEXITCODE = $global:LASTEXITCODE
    $errorCode = 0
    if ($lastCommandSuccess -eq $false) {
        #native app exit code
-       if ($realLASTEXITCODE -ne 0) {
+       if ($realLASTEXITCODE -is [int]) {

...

All 16 comments

Pretty sure that's an issue in how you invoke this in Powershell rather than an issue from OMP as I can't reproduce this anywhere. Did you do a manual configuration or are you using the module?

image

I installed oh-my-posh manually instead of module.

I installed oh-my-posh manually instead of module.

Can you share how you set it up? Probably something is off.

Completely follow the manual installation docs

  1. download
mkdir C:\tools
Invoke-Webrequest https://github.com/JanDeDobbeleer/oh-my-posh3/releases/latest/download/posh-windows-amd64.exe -OutFile C:\tools\oh-my-posh.exe
mkdir ~\.poshthemes
Invoke-Webrequest https://github.com/JanDeDobbeleer/oh-my-posh3/releases/latest/download/themes.zip -OutFile ~\.poshthemes\themes.zip
Expand-Archive ~\.poshthemes\themes.zip -DestinationPath ~\.poshthemes -Force
Remove-Item ~\.poshthemes\themes.zip
  1. edit $profile
[ScriptBlock]$Prompt = {
    $lastCommandSuccess = $?
    $realLASTEXITCODE = $global:LASTEXITCODE
    $errorCode = 0
    if ($lastCommandSuccess -eq $false) {
        #native app exit code
        if ($realLASTEXITCODE -ne 0) {
            $errorCode = $realLASTEXITCODE
        }
        else {
            $errorCode = 1
        }
    }
    $startInfo = New-Object System.Diagnostics.ProcessStartInfo
    $startInfo.FileName = "C:\tools\oh-my-posh.exe"
    $cleanPWD = $PWD.ProviderPath.TrimEnd("\")
    $startInfo.Arguments = "-config=""$env:USERPROFILE\.poshthemes\jandedobbeleer.json"" -error=$errorCode -pwd=""$cleanPWD"""
    $startInfo.Environment["TERM"] = "xterm-256color"
    $startInfo.CreateNoWindow = $true
    $startInfo.StandardOutputEncoding = [System.Text.Encoding]::UTF8
    $startInfo.RedirectStandardOutput = $true
    $startInfo.UseShellExecute = $false
    if ($PWD.Provider.Name -eq 'FileSystem') {
      $startInfo.WorkingDirectory = $PWD.ProviderPath
    }
    $process = New-Object System.Diagnostics.Process
    $process.StartInfo = $startInfo
    $process.Start() | Out-Null
    $standardOut = $process.StandardOutput.ReadToEnd()
    $process.WaitForExit()
    $standardOut
    $global:LASTEXITCODE = $realLASTEXITCODE
    #remove temp variables
    Remove-Variable realLASTEXITCODE -Confirm:$false
    Remove-Variable lastCommandSuccess -Confirm:$false
}
Set-Item -Path Function:prompt -Value $Prompt -Force
  1. over

If the first execution after installation is OK, reopening the terminal will cause problems. @JanDeDobbeleer

@Vixb1122 do ma a favor, install the powershell module to see if that makes a difference. I can have a look this evening to see what's off between the manual installation guide and the module logic (not much, but there will be something).

Same error:

PS C:\Users\Vixb> Set-PoshPrompt -Theme ~\.poshthemes\sorin.json
 Vixb@Vixb-PC  ~ ❯❯❯ kajs
kajs: The term 'kajs' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
PS>

The reason is that $global:LASTEXITCODE can be empty. This fixes it:

[ScriptBlock]$Prompt = {
    $lastCommandSuccess = $?
    $realLASTEXITCODE = $global:LASTEXITCODE
    $errorCode = 0
    if ($lastCommandSuccess -eq $false) {
        #native app exit code
-       if ($realLASTEXITCODE -ne 0) {
+       if ($realLASTEXITCODE -is [int]) {

...

@WolfspiritM thx, that is useful.

@WolfspiritM thx for the quick fix!

@JanDeDobbeleer
There is a new issue (or a legacy issue.): after every command execution error, an unfamiliar character(퀍) will appear.
And The first execution after installation is OK,

❯❯  Vixb  23:24  tlaksj
tlaksj: The term 'tlaksj' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
❯❯  Vixb 퀍  23:25  kajs
kajs: The term 'kajs' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
❯❯  Vixb 퀍  23:30

That's probably the exit segment.

@JanDeDobbeleer Ok, You are right. \uD00D -> 퀍

You can override it with something else, when using a Nerd Font it should be something else.

Alright, some characters are missing from some Nerd Font. e.g.: FiraCode NF
image

That's possible. Which is why you can easily override these. As indicated, the font I use is Meslo. Most of the fonts I checked do work as it uses the NF cheat sheet.

Was this page helpful?
0 / 5 - 0 ratings