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

Unrecognized commands cause the theme to not work #193

Closed Vixb1122 closed 3 years ago

Vixb1122 commented 3 years ago

Prerequisites

Description

Unrecognized commands cause the theme to not work

Environment

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
JanDeDobbeleer commented 3 years ago

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
Vixb1122 commented 3 years ago

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

JanDeDobbeleer commented 3 years ago

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

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

Vixb1122 commented 3 years ago

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
  2. 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
  3. over
Vixb1122 commented 3 years ago

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

JanDeDobbeleer commented 3 years ago

@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).

Vixb1122 commented 3 years ago

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>
WolfspiritM commented 3 years ago

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]) {

...
Vixb1122 commented 3 years ago

@WolfspiritM thx, that is useful.

JanDeDobbeleer commented 3 years ago

@WolfspiritM thx for the quick fix!

Vixb1122 commented 3 years ago

@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
JanDeDobbeleer commented 3 years ago

That's probably the exit segment.

Vixb1122 commented 3 years ago

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

JanDeDobbeleer commented 3 years ago

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

Vixb1122 commented 3 years ago

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

JanDeDobbeleer commented 3 years ago

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.

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