JanDeDobbeleer / oh-my-posh

The most customisable and low-latency cross platform/shell prompt renderer
https://ohmyposh.dev
MIT License
17.41k stars 2.38k forks source link

Oh My Posh not setting theme on windows terminal #1773

Closed sravanpannala closed 2 years ago

sravanpannala commented 2 years ago

Code of Conduct

What happened?

Oh My Posh suddenly stopped working on Powershell in the Windows Terminal App (and in other places). Here is how the powershell looks now image

Theme

I use the blue-owl theme normally which isn't working. I tried other themes and none of them are working. I set the theme using this line in my $profile oh-my-posh --init --shell pwsh --config "~/AppData/Local/Programs/oh-my-posh/themes/blue-owl.omp.json" | Invoke-Expression

Write-PoshDebug (PowerShell) is just returning Loading personal and system profiles took 803ms. and nothing else. I'm posting the result of Write-PoshDebug below

What OS are you seeing the problem on?

Windows

Which shell are you using?

powershell

Log output

Version: 7.18.0

Segments:

ConsoleTitle(false) -   0 ms -
session(true)  -   0 ms -  pansr@Sravan-Spectre 
path(true)     -   0 ms -  pansr
shell(true)    -   0 ms -  pwsh
text(true)     -   0 ms -  no config
exit(true)     -   1 ms -  

Run duration: 2.2573ms

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

Logs:

2022/02/17 18:56:33 Args duration: 0s, args:
2022/02/17 18:56:33 Args duration: 0s, args:
2022/02/17 18:56:33 Args duration: 0s, args:
2022/02/17 18:56:33 Shell duration: 15.139ms, args:
2022/02/17 18:56:33 debug: Getenv

2022/02/17 18:56:33 Getenv duration: 0s, args: OMP_CACHE_DISABLED
2022/02/17 18:56:33 debug: Pwd
C:\Users\pansr
2022/02/17 18:56:33 Pwd duration: 0s, args:
2022/02/17 18:56:33 debug: Home
C:\SPB_Data
2022/02/17 18:56:33 PathSeperator duration: 0s, args:
2022/02/17 18:56:33 PathSeperator duration: 0s, args:
2022/02/17 18:56:33 PathSeperator duration: 0s, args:
2022/02/17 18:56:33 PathSeperator duration: 0s, args:
2022/02/17 18:56:33 PathSeperator duration: 0s, args:
2022/02/17 18:56:33 PathSeperator duration: 0s, args:
2022/02/17 18:56:33 PathSeperator duration: 0s, args:
2022/02/17 18:56:33 debug: Pwd
C:\Users\pansr
2022/02/17 18:56:33 Pwd duration: 0s, args:
2022/02/17 18:56:33 debug: Home
C:\SPB_Data
2022/02/17 18:56:33 debug: Getenv

2022/02/17 18:56:33 Getenv duration: 0s, args: SSH_CONNECTION
2022/02/17 18:56:33 debug: Getenv

2022/02/17 18:56:33 Getenv duration: 0s, args: SSH_CLIENT
2022/02/17 18:56:33 Root duration: 0s, args:
2022/02/17 18:56:33 Shell duration: 0s, args:
2022/02/17 18:56:33 ErrorCode duration: 0s, args:
2022/02/17 18:56:33 IsWsl duration: 0s, args:
2022/02/17 18:56:33 debug: Pwd
C:\Users\pansr
2022/02/17 18:56:33 Pwd duration: 0s, args:
2022/02/17 18:56:33 debug: Home
C:\SPB_Data
2022/02/17 18:56:33 PathSeperator duration: 0s, args:
2022/02/17 18:56:33 PathSeperator duration: 0s, args:
2022/02/17 18:56:33 PathSeperator duration: 0s, args:
2022/02/17 18:56:33 PathSeperator duration: 0s, args:
2022/02/17 18:56:33 PathSeperator duration: 0s, args:
2022/02/17 18:56:33 PathSeperator duration: 0s, args:
2022/02/17 18:56:33 PathSeperator duration: 0s, args:
2022/02/17 18:56:33 User duration: 0s, args:
2022/02/17 18:56:33 Host duration: 0s, args:
2022/02/17 18:56:33 GOOS duration: 0s, args:
2022/02/17 18:56:33 TemplateCache duration: 0s, args:
2022/02/17 18:56:33 debug: Pwd
C:\Users\pansr
2022/02/17 18:56:33 Pwd duration: 0s, args:
2022/02/17 18:56:33 debug: Home
C:\SPB_Data
2022/02/17 18:56:33 debug: Pwd
C:\Users\pansr
2022/02/17 18:56:33 Pwd duration: 0s, args:
2022/02/17 18:56:33 Args duration: 0s, args:
2022/02/17 18:56:33 debug: Home
C:\SPB_Data
2022/02/17 18:56:33 GOOS duration: 0s, args:
2022/02/17 18:56:33 GOOS duration: 0s, args:
2022/02/17 18:56:33 PathSeperator duration: 0s, args:
2022/02/17 18:56:33 PathSeperator duration: 0s, args:
2022/02/17 18:56:33 PathSeperator duration: 0s, args:
2022/02/17 18:56:33 PathSeperator duration: 0s, args:
2022/02/17 18:56:33 PathSeperator duration: 0s, args:
2022/02/17 18:56:33 PathSeperator duration: 0s, args:
2022/02/17 18:56:33 PathSeperator duration: 0s, args:
2022/02/17 18:56:33 PathSeperator duration: 0s, args:
2022/02/17 18:56:33 GOOS duration: 0s, args:
2022/02/17 18:56:33 IsWsl duration: 0s, args:
2022/02/17 18:56:33 StackCount duration: 0s, args:
2022/02/17 18:56:33 TemplateCache duration: 0s, args:
2022/02/17 18:56:33 debug: Pwd
C:\Users\pansr
2022/02/17 18:56:33 Pwd duration: 0s, args:
2022/02/17 18:56:33 debug: Home
C:\SPB_Data
2022/02/17 18:56:33 Shell duration: 0s, args:
2022/02/17 18:56:33 TemplateCache duration: 0s, args:
2022/02/17 18:56:33 debug: Pwd
C:\Users\pansr
2022/02/17 18:56:33 Pwd duration: 0s, args:
2022/02/17 18:56:33 debug: Home
C:\SPB_Data
2022/02/17 18:56:33 TemplateCache duration: 0s, args:
2022/02/17 18:56:33 debug: Pwd
C:\Users\pansr
2022/02/17 18:56:33 Pwd duration: 0s, args:
2022/02/17 18:56:33 debug: Home
C:\SPB_Data
2022/02/17 18:56:33 ErrorCode duration: 0s, args:
2022/02/17 18:56:33 TemplateCache duration: 0s, args:
2022/02/17 18:56:33 TemplateCache duration: 0s, args:
2022/02/17 18:56:33 TemplateCache duration: 0s, args:
2022/02/17 18:56:33 debug: Getenv
C:\Users\pansr\AppData\Local
2022/02/17 18:56:33 Getenv duration: 0s, args: LOCALAPPDATA
2022/02/17 18:56:33 CachePath duration: 0s, args:
prokopto-dev commented 2 years ago

@sravanpannala : Now I haven't looked into this on Windows at all yet, but I noted that the homebrew-methods via Linux and MacOS now have a /share/ subfolder added before the /themes/; this causes older paths to fail when referencing the internal theme folder.

If you recently updated oh-my-posh, that may be part of the issue at hand.

Otherwise, it may be worth digging into further.

I suggest that because it looks like the system isn't passing anything to the parser; since they're simply JSON files, I'd be hard pressed to think of a way that it'd be broken other than:

sravanpannala commented 2 years ago

That is true, oh-my-posh stopped working after the recent update. I don't think it is a path issue because I'm referencing the path location directly without using variables: ~/AppData/Local/Programs/oh-my-posh/themes/blue-owl.omp.json. I have verified that the file exists in the location.

prokopto-dev commented 2 years ago

Okay; I’ll have a look at what I can find; On that note: What version of windows are you using? I’ll boot up my windows box and see if I can’t emulate or reproduce and debug.

On Feb 18, 2022, at 09:13, Sravan Pannala @.***> wrote:

 That is true, oh-my-posh stopped working after the recent update. I don't think it is a path issue because I'm referencing the path location directly without using variables: ~/AppData/Local/Programs/oh-my-posh/themes/blue-owl.omp.json. I have verified that the file exists in the location.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.

sravanpannala commented 2 years ago

I'm using Windows 10 Home Version: 10.0.19044 Build 19044 PowerShell 7.2.1

JanDeDobbeleer commented 2 years ago

@CapularisPerpetua when the parser fails it prints that error, this actually implies that the flag isn't set. In any other case it will print the actual issue. @sravanpannala are you certain the hyphens are correct? As there are different hyphens out there.

sravanpannala commented 2 years ago

I think the hyphens are correct because they worked before. This problem started only 2 days ago.

sravanpannala commented 2 years ago

I tried reinstalling oh-my-posh via different methods. Chocolatey and Winget still didn't work. Installing it via Install-Module oh-my-posh -Scope CurrentUser solved the issue and I can set themes now.

sravanpannala commented 2 years ago

I think I figured out what the issue is: I was setting the path to the config files earlier as "~/AppData/Local/Programs/oh-my-posh/themes/blue-owl.omp.json" Changing it to "C:/Users/pansr/AppData/Local/Programs/oh-my-posh/themes/blue-owl.omp.json" solved the issue. I think something changed in the code which refers to the home folder. So now the home folder is not showing the home icon image

prokopto-dev commented 2 years ago

Interesting. So its now asking for absolute paths... sounds like something somewhere isn't expanding as expected.

JanDeDobbeleer commented 2 years ago

@CapularisPerpetua @sravanpannala you can't expand ~ from golang without replacing it. Which is what we do.

JanDeDobbeleer commented 2 years ago

@sravanpannala I tried to reproduce your issue and it's simply impossible.

image

To resolve the HOME path we validate the following. Can you provide the output of these env vars?

kennedy commented 2 years ago

For those who installed oh-my-posh with scoop, make sure your $PROFILE is using $(scoop prefix oh-my-posh)

oh-my-posh --init --shell pwsh --config "$(scoop prefix oh-my-posh)\themes\robbyrussel.omp.json" | Invoke-Expression
JanDeDobbeleer commented 2 years ago

@kennedy I'm looking to restructure the docs so these elements can be easily added. It's a limitation of docusaurus that you can't yet work with variables.

KevinGastelum commented 2 years ago

I'm having the same problem with Windows Terminal defaulting back to its basic look each time I close it. ``

JanDeDobbeleer commented 2 years ago

@KevinGastelum did you add the oh-my-posh init line to your PowerShell profile or shell specific rc file?

JanDeDobbeleer commented 2 years ago

@sravanpannala can you share the output of oh-my-posh --config "~/AppData/Local/Programs/oh-my-posh/themes/blue-owl.omp.json" --shell pwsh --print-init

sravanpannala commented 2 years ago

Here you go:

# Powershell doesn't default to UTF8 just yet, so we're forcing it as there are too many problems
# that pop up when we don't
if ($ExecutionContext.SessionState.LanguageMode -ne "ConstrainedLanguage") {
    [console]::InputEncoding = [console]::OutputEncoding = New-Object System.Text.UTF8Encoding
}
elseif ($env:POSH_CONSTRAINED_LANGUAGE_MODE -ne $true) {
    Write-Host "[WARNING] ConstrainedLanguage mode detected, unable to set console to UTF-8.
When using PowerShell in ConstrainedLanguage mode, please set the
console mode manually to UTF-8. See here for more information:
https://ohmyposh.dev/docs/faq#powershell-running-in-constrainedlanguage-mode
"
}

$env:POWERLINE_COMMAND = "oh-my-posh"
$env:CONDA_PROMPT_MODIFIER = $false

# specific module support (disabled by default)
$omp_value = $env:POSH_GIT_ENABLED
if ($null -eq $omp_value) {
    $env:POSH_GIT_ENABLED = $false
}

# used to detect empty hit
$global:omp_lastHistoryId = -1

$omp_config = "C:\SPB_Data\AppData\Local\Programs\oh-my-posh\themes\blue-owl.omp.json"
if (Test-Path $omp_config) {
    $env:POSH_THEME = (Resolve-Path -Path $omp_config).ProviderPath
}

Remove-Variable omp_value -Confirm:$false
Remove-Variable omp_config -Confirm:$false

# set secondary prompt
$secondaryPrompt = @(&"C:/Users/pansr/AppData/Local/Programs/oh-my-posh/bin/oh-my-posh.exe" --config="$Env:POSH_THEME" --print-secondary 2>&1) -join "`n"
Set-PSReadLineOption -ContinuationPrompt $secondaryPrompt

function global:Set-PoshContext {}

function global:Get-PoshContext {
    $config = $env:POSH_THEME
    $cleanPWD = $PWD.ProviderPath
    $cleanPSWD = $PWD.ToString()
    return $config, $cleanPWD, $cleanPSWD
}

function global:Initialize-ModuleSupport {
    if ($env:POSH_GIT_ENABLED -eq $true -and (Get-Module -Name "posh-git")) {
        [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSProvideCommentHelp', '', Justification = 'Variable used later(not in this scope)')]
        $global:GitStatus = Get-GitStatus
        $env:POSH_GIT_STATUS = Write-GitStatus -Status $global:GitStatus
    }
}

[ScriptBlock]$Prompt = {
    #store if the last command was successful
    $lastCommandSuccess = $?
    #store the last exit code for restore
    $realLASTEXITCODE = $global:LASTEXITCODE
    $omp = "C:/Users/pansr/AppData/Local/Programs/oh-my-posh/bin/oh-my-posh.exe"
    $config, $cleanPWD, $cleanPSWD = Get-PoshContext
    if ($env:POSH_TRANSIENT -eq $true) {
        $standardOut = @(&$omp --pwd="$cleanPWD" --pswd="$cleanPSWD" --config="$config" --print-transient 2>&1)
        $standardOut -join "`n"
        $env:POSH_TRANSIENT = $false
        return
    }
    $errorCode = 0
    Initialize-ModuleSupport
    Set-PoshContext
    if ($lastCommandSuccess -eq $false) {
        #native app exit code
        if ($realLASTEXITCODE -is [int] -and $realLASTEXITCODE -gt 0) {
            $errorCode = $realLASTEXITCODE
        }
        else {
            $errorCode = 1
        }
    }

    # read stack count from current stack(if invoked from profile=right value,otherwise use the global variable set in Set-PoshPrompt(stack scoped to module))
    $stackCount = (Get-Location -stack).Count
    try {
        if ($global:omp_global_sessionstate -ne $null) {
            $stackCount = ($global:omp_global_sessionstate).path.locationstack('').count
        }
    }
    catch {}

    $executionTime = -1
    $history = Get-History -ErrorAction Ignore -Count 1
    if ($null -ne $history -and $null -ne $history.EndExecutionTime -and $null -ne $history.StartExecutionTime -and $global:omp_lastHistoryId -ne $history.Id) {
        $executionTime = ($history.EndExecutionTime - $history.StartExecutionTime).TotalMilliseconds
        $global:omp_lastHistoryId = $history.Id
    }
    $terminalWidth = $Host.UI.RawUI.WindowSize.Width
    $standardOut = @(&$omp --error="$errorCode" --pwd="$cleanPWD" --pswd="$cleanPSWD" --execution-time="$executionTime" --stack-count="$stackCount" --config="$config" --terminal-width=$terminalWidth 2>&1)
    # make sure PSReadLine knows we have a multiline prompt
    $extraLines = $standardOut.Count - 1
    if ($extraLines -gt 0) {
        Set-PSReadlineOption -ExtraPromptLineCount $extraLines
    }
    # the output can be multiline, joining these ensures proper rendering by adding line breaks with `n
    $standardOut -join "`n"
    $global:LASTEXITCODE = $realLASTEXITCODE
    #remove temp variables
    Remove-Variable realLASTEXITCODE -Confirm:$false
    Remove-Variable lastCommandSuccess -Confirm:$false
}
Set-Item -Path Function:prompt -Value $Prompt -Force

function global:Write-PoshDebug {
    $omp = "C:/Users/pansr/AppData/Local/Programs/oh-my-posh/bin/oh-my-posh.exe"
    $config, $cleanPWD, $cleanPSWD = Get-PoshContext
    $standardOut = @(&$omp --error=1337 --pwd="$cleanPWD" --pswd="$cleanPSWD" --execution-time=9001 --config="$config" --debug 2>&1)
    $standardOut -join "`n"
}

<#
.SYNOPSIS
    Exports the current oh-my-posh theme
.DESCRIPTION
    By default the config is exported in json to the clipboard
.EXAMPLE
    Export-PoshTheme
    Current theme exported in json to clipboard
.EXAMPLE
    Export-PoshTheme -Format toml
    Current theme exported in toml to clipboard
.EXAMPLE
    Export-PoshTheme c:\temp\theme.toml toml
    Current theme exported in toml to c:\temp\theme.toml
.EXAMPLE
    Export-PoshTheme ~\theme.toml toml
    Current theme exported in toml to your home\theme.toml
#>
function global:Export-PoshTheme {
    param(
        [Parameter(Mandatory = $false)]
        [string]
        # The file path where the theme will be exported. If not provided, the config is copied to the clipboard by default.
        $FilePath,
        [Parameter(Mandatory = $false)]
        [ValidateSet('json', 'yaml', 'toml')]
        [string]
        # The format of the theme
        $Format = 'json'
    )

    $config = $env:POSH_THEME
    $omp = "C:/Users/pansr/AppData/Local/Programs/oh-my-posh/bin/oh-my-posh.exe"
    $configString = @(&$omp --config="$config" --config-format="$Format" --print-config 2>&1)
    # if no path, copy to clipboard by default
    if ($FilePath -ne "") {
        #https://stackoverflow.com/questions/3038337/powershell-resolve-path-that-might-not-exist
        $FilePath = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($FilePath)
        [IO.File]::WriteAllLines($FilePath, $configString)
    }
    else {
        Set-Clipboard $configString
        Write-Output "Theme copied to clipboard"
    }
}

function global:Export-PoshImage {
    param(
        [Parameter(Mandatory = $false)]
        [int]
        $RPromptOffset = 40,
        [Parameter(Mandatory = $false)]
        [int]
        $CursorPadding = 30,
        [Parameter(Mandatory = $false)]
        [string]
        $Author,
        [Parameter(Mandatory = $false)]
        [string]
        $BGColor
    )

    if ($Author) {
        $Author = "--author=$Author"
    }
    if ($BGColor) {
        $BGColor = "--bg-color=$BGColor"
    }

    $omp = "C:/Users/pansr/AppData/Local/Programs/oh-my-posh/bin/oh-my-posh.exe"
    $config, $cleanPWD, $cleanPSWD = Get-PoshContext
    $standardOut = @(&$omp --shell=shell --config="$config" --pwd="$cleanPWD" --pswd="$cleanPSWD" --export-png --rprompt-offset="$RPromptOffset" --cursor-padding="$CursorPadding" $Author $BGColor 2>&1)
    $standardOut -join "`n"
}

function global:Enable-PoshTooltips {
    Set-PSReadlineKeyHandler -Key SpaceBar -ScriptBlock {
        [Microsoft.PowerShell.PSConsoleReadLine]::Insert(' ')
        $position = $host.UI.RawUI.CursorPosition
        $omp = "C:/Users/pansr/AppData/Local/Programs/oh-my-posh/bin/oh-my-posh.exe"
        $config, $cleanPWD, $cleanPSWD = Get-PoshContext
        $command = $null
        $cursor = $null
        [Microsoft.PowerShell.PSConsoleReadLine]::GetBufferState([ref]$command, [ref]$cursor)
        $standardOut = @(&$omp --pwd="$cleanPWD" --pswd="$cleanPSWD" --config="$config" --command="$command" 2>&1)
        Write-Host $standardOut -NoNewline
        $host.UI.RawUI.CursorPosition = $position
    }
}

function global:Enable-PoshTransientPrompt {
    Set-PSReadlineKeyHandler -Key Enter -ScriptBlock {
        $env:POSH_TRANSIENT = $true
        [Microsoft.PowerShell.PSConsoleReadLine]::InvokePrompt()
        [Microsoft.PowerShell.PSConsoleReadLine]::AcceptLine()
    }
}

function global:Enable-PoshLineError {
    $omp = "C:/Users/pansr/AppData/Local/Programs/oh-my-posh/bin/oh-my-posh.exe"
    $validLine = @(&$omp --config="$Env:POSH_THEME" --print-valid 2>&1) -join "`n"
    $errorLine = @(&$omp --config="$Env:POSH_THEME" --print-error 2>&1) -join "`n"
    Set-PSReadLineOption -PromptText $validLine, $errorLine
}

<#
 .SYNOPSIS
     Returns an ansi formatted hyperlink
     if name not set, uri is used as the name of the hyperlink
 .EXAMPLE
     Get-Hyperlink
 #>
function global:Get-Hyperlink {
    param(
        [Parameter(Mandatory, ValuefromPipeline = $True)]
        [string]$uri,
        [Parameter(ValuefromPipeline = $True)]
        [string]$name
    )
    $esc = [char]27
    if ("" -eq $name) {
        $name = $uri
    }
    if ($null -ne $env:WSL_DISTRO_NAME) {
        # wsl conversion if needed
        $uri = &wslpath -m $uri
    }
    return "$esc]8;;file://$uri$esc\$name$esc]8;;$esc\"
}

function global:Get-PoshThemes() {
    param(
        [Parameter(Mandatory = $false, HelpMessage = "The themes folder")]
        [string]
        $Path = $env:POSH_THEMES_PATH,
        [switch]
        [Parameter(Mandatory = $false, HelpMessage = "List themes path")]
        $List
    )

    if ($Path -eq "") {
        do {
            $temp = Read-Host 'Please enter the themes path'
        }
        while (-not (Test-Path -Path $temp))
        $Path = (Resolve-Path -Path $temp).ProviderPath
    }

    $logo = @'
   __  _____ _      ___  ___       ______         _      __
  / / |  _  | |     |  \/  |       | ___ \       | |     \ \
 / /  | | | | |__   | .  . |_   _  | |_/ /__  ___| |__    \ \
< <   | | | | '_ \  | |\/| | | | | |  __/ _ \/ __| '_ \    > >
 \ \  \ \_/ / | | | | |  | | |_| | | | | (_) \__ \ | | |  / /
  \_\  \___/|_| |_| \_|  |_/\__, | \_|  \___/|___/_| |_| /_/
                             __/ |
                            |___/
'@
    Write-Host $logo
    $themes = Get-ChildItem -Path "$Path\*" -Include '*.omp.json' | Sort-Object Name
    if ($List -eq $true) {
        $themes | Select-Object @{ Name = 'hyperlink'; Expression = { Get-Hyperlink -uri $_.fullname } } | Format-Table -HideTableHeaders
    }
    else {
        $omp = "C:/Users/pansr/AppData/Local/Programs/oh-my-posh/bin/oh-my-posh.exe"
        $themes | ForEach-Object -Process {
            Write-Host "Theme: $(Get-Hyperlink -uri $_.fullname -name $_.BaseName.Replace('.omp', ''))"
            Write-Host ""
            & $omp -config $($_.FullName) -pwd $PWD -shell pwsh
            Write-Host ""
            Write-Host ""
        }
    }
    Write-Host ""
    Write-Host "Themes location: $(Get-Hyperlink -uri "$Path")"
    Write-Host ""
    Write-Host "To change your theme, adjust the init script in $PROFILE."
    Write-Host "Example:"
    Write-Host "  oh-my-posh --init --shell pwsh --config $Path/jandedobbeleer.omp.json | Invoke-Expression"
    Write-Host ""
}
sravanpannala commented 2 years ago

Regarding the home variables:

$env:HOME
C:\SPB_Data
$env:HOMEPATH
\Users\pansr
$env:HOMEDRIVE
C:
$env:USERPROFILE
C:\Users\pansr
KevinGastelum commented 2 years ago

@JanDeDobbeleer I did, but when I start my windows terminal I get "The term 'oh-my-posh' is not recognized as the name of a cmdlet, function, script file, or operable program."

JanDeDobbeleer commented 2 years ago

@KevinGastelum if you installed using the PowerShell module, make sure to also import it first to set the PATH correctly.

JanDeDobbeleer commented 2 years ago

@sravanpannala this is key (seems correct at first sight):

$omp_config = "C:\SPB_Data\AppData\Local\Programs\oh-my-posh\themes\blue-owl.omp.json"
if (Test-Path $omp_config) {
    $env:POSH_THEME = (Resolve-Path -Path $omp_config).ProviderPath
}

In your shell, what's the value of $env:POSH_THEME?

sravanpannala commented 2 years ago

The value is

C:\Users\pansr\AppData\Local\Programs\oh-my-posh\themes\jblab_2021.omp.json

because I'm setting it explicitly

oh-my-posh --init --shell pwsh --config "C:/Users/pansr/AppData/Local/Programs/oh-my-posh/themes/jblab_2021.omp.json" | Invoke-Expression
JanDeDobbeleer commented 2 years ago

@sravanpannala ah ok, but that worked, right? I'm looking for the case it doesn't work like in oh-my-posh --config "~/AppData/Local/Programs/oh-my-posh/themes/blue-owl.omp.json" --shell pwsh --print-init because if it resolves I have no idea what's going wrong here.

JanDeDobbeleer commented 2 years ago

@sravanpannala can you try again on the latest release (7.28.1)?

jbonnier commented 2 years ago

Could it be a problem with ~/.bash_profile, ~/.bashrc and ~/.profile . If .profile or .bash_profile exists and these files are not loading .bashrc, you might have this kind of problem. Some files might take precedence over others.

sravanpannala commented 2 years ago

@JanDeDobbeleer It is working with the latest version 7.29.0. Also I think some program changed my home path as I referred before:

$env:HOME
C:\SPB_Data

Changing it back to

$env:HOME
C:\Users\pansr

Solved the issue. You can close this issue. Thanks a lot for your help. I learnt a lot during this

icaroperetti commented 2 years ago

Hey guys. I'm having a issue with oh-my-posh if i execute oh-my-posh --init --shell pwsh --config "~/AppData/Local/Programs/oh-my-posh/themes/robbyrussel.omp.json" | Invoke-Expression it change the theme, but if I close my terminal again the old theme is set. I tried configuring robbyrussel theme in $PROFILE too

JanDeDobbeleer commented 2 years ago

@icaroperetti what do you have in your $PROFILE?

icaroperetti commented 2 years ago

I solved adding the following command in my $PROFILE oh-my-posh --init --shell pwsh --config "~/AppData/Local/Programs/oh-my-posh/themes/the-unnamed.omp.json" | Invoke-Expression

SpaceTesla commented 2 years ago

I solved adding de following command in my $PROFILE oh-my-posh --init --shell pwsh --config "~/AppData/Local/Programs/oh-my-posh/themes/the-unnamed.omp.json" | Invoke-Expression

Well, I tried this and it still didn't work for me. I get this output (@(& 'C:/Users/shiva/scoop/apps/oh-my-posh/current/bin/oh-my-posh.exe' init pwsh --config='C:\Users\shiva\scoop\apps\oh-my-posh\current\themes\jandedobbeleer.omp.json' --print) -join "n") | Invoke-Expression`

What should I do to fix this?

icaroperetti commented 2 years ago

https://github.com/icaroperetti/oh-my-posh-config-windows I added everything I've done in this repository. If you want to try to see if it works

JanDeDobbeleer commented 2 years ago

@SpaceTesla I have the impression you forgot to add Invoke-Expression to the init line, please go through the guide and follow everything to the letter. There aren't that many steps.

ghost commented 1 year ago

@JanDeDobbeleer, default PowerShell 5 for Windows 11. The automation in 7 is starting to trip me up instead of help me.

 jasen@Bertha  ~ 
❯ oh-my-posh init pwsh --config "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/stelbent.minimal.omp.json" | Invoke-Expression
Get-PSReadLineKeyHandler : A parameter cannot be found that matches parameter name 'Key'.
At line:391 char:43
+             if ((Get-PSReadLineKeyHandler -Key Spacebar).Function -eq ...
+                                           ~~~~
    + CategoryInfo          : InvalidArgument: (:) [Get-PSReadLineKeyHandler], ParameterBindingException
    + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.GetKeyHandlerCommand

Get-PSReadLineKeyHandler : A parameter cannot be found that matches parameter name 'Key'.
At line:394 char:43
+             if ((Get-PSReadLineKeyHandler -Key Enter).Function -eq 'O ...
+                                           ~~~~
    + CategoryInfo          : InvalidArgument: (:) [Get-PSReadLineKeyHandler], ParameterBindingException
    + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.GetKeyHandlerCommand

                                                                                                        pwsh | 19:36:59
┌ jasen@Bertha  ~ 
└ $ oh-my-posh --config "~/AppData/Local/Programs/oh-my-posh/themes/blue-owl.omp.json" --shell pwsh --print-init
Error: unknown flag: --print-init
Usage:
  oh-my-posh [flags]
  oh-my-posh [command]

Available Commands:
  cache       Interact with the oh-my-posh cache
  completion  Generate the autocompletion script for the specified shell
  config      Interact with the config
  debug       Print the prompt in debug mode
  font        Manage fonts
  get         Get a value from oh-my-posh
  help        Help about any command
  init        Initialize your shell and config
  print       Print the prompt/context
  prompt      Set up the prompt for your shell (deprecated)
  toggle      Toggle a segment on/off
  version     Print the version

Flags:
  -c, --config string   config (required)
  -h, --help            help for oh-my-posh
  -i, --init            init (deprecated)
  -s, --shell string    shell (deprecated)
      --version         version

Use "oh-my-posh [command] --help" for more information about a command.

                                                                                                        pwsh | 19:38:21
┌ jasen@Bertha  ~  error 
└ $ $omp_config = "C:\SPB_Data\AppData\Local\Programs\oh-my-posh\themes\blue-owl.omp.json"
                                                                                                                                           pwsh | 19:42:08
┌ jasen@Bertha  ~ 
└ $ if (Test-Path $omp_config) {
>     $env:POSH_THEME = (Resolve-Path -Path $omp_config).ProviderPath
> }
                                                                                                                                           pwsh | 19:42:10
┌ jasen@Bertha  ~ 
└ $ oh-my-posh init pwsh --config "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/stelbent.minimal.omp.json" | Invoke-Expression
Get-PSReadLineKeyHandler : A parameter cannot be found that matches parameter name 'Key'.
At line:391 char:43
+             if ((Get-PSReadLineKeyHandler -Key Spacebar).Function -eq ...
+                                           ~~~~
    + CategoryInfo          : InvalidArgument: (:) [Get-PSReadLineKeyHandler], ParameterBindingException
    + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.GetKeyHandlerCommand

Get-PSReadLineKeyHandler : A parameter cannot be found that matches parameter name 'Key'.
At line:394 char:43
+             if ((Get-PSReadLineKeyHandler -Key Enter).Function -eq 'O ...
+                                           ~~~~
    + CategoryInfo          : InvalidArgument: (:) [Get-PSReadLineKeyHandler], ParameterBindingException
    + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.GetKeyHandlerCommand

                                                                                                                                           pwsh | 19:42:52
┌ jasen@Bertha  ~ 
└ $ $env:home
                                                                                                                                           pwsh | 19:43:13
┌ jasen@Bertha  ~ 
└ $ env:home
env:home : The term 'env:home' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or
if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ env:home
+ ~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (env:home:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

                                                                                                                                           pwsh | 19:43:17
┌ jasen@Bertha  ~  error 
└ $ print env:home
Unable to initialize device PRN
                                                                                                                                           pwsh | 19:43:20
┌ jasen@Bertha  ~ 
└ $ echo

cmdlet Write-Output at command pipeline position 1
Supply values for the following parameters:
InputObject[0]: env:home
InputObject[1]:
                                                                                                                                           pwsh | 19:43:39
┌ jasen@Bertha  ~ 
└ $ echo $env:home
                                                                                                                                           pwsh | 19:43:46
┌ jasen@Bertha  ~ 
└ $ echo $env:HOME
                                                                                                                                           pwsh | 19:44:15
┌ jasen@Bertha  ~ 
└ $ echo $env:HOMEPATH
\Users\jasen
                                                                                                                                           pwsh | 19:44:18
┌ jasen@Bertha  ~ 
└ $ echo $env:HOMEDRIVE
C:
                                                                                                                                           pwsh | 19:44:23
┌ jasen@Bertha  ~ 
└ $ echo $env:USERPROFILE
C:\Users\jasen
                                                                                                                                           pwsh | 19:44:37
┌ jasen@Bertha  ~ 
└ $ oh-my-posh init pwsh --config "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/blue-owl.omp.json" | Invoke-Expression
Get-PSReadLineKeyHandler : A parameter cannot be found that matches parameter name 'Key'.
At line:391 char:43
+             if ((Get-PSReadLineKeyHandler -Key Spacebar).Function -eq ...
+                                           ~~~~
    + CategoryInfo          : InvalidArgument: (:) [Get-PSReadLineKeyHandler], ParameterBindingException
    + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.GetKeyHandlerCommand

Get-PSReadLineKeyHandler : A parameter cannot be found that matches parameter name 'Key'.
At line:394 char:43
+             if ((Get-PSReadLineKeyHandler -Key Enter).Function -eq 'O ...
+                                           ~~~~
    + CategoryInfo          : InvalidArgument: (:) [Get-PSReadLineKeyHandler], ParameterBindingException
    + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.GetKeyHandlerCommand

    0.287s                                                                                                              jasen / Bertha  19:45:24
❯
ghost commented 1 year ago

@JanDeDobbeleer, cancel. My $PROFILE was referencing a conflicting theme.

ask-sup commented 1 year ago

Greetings. The problem persists up to this day. Basically, i've installed oh-my-posh from scoop and $evn:POSH_THEMES_PATH variable contains a wrong path. It misses one folder - "Program". As previously mentioned i've used a longer path from %AppData% entry point and it worked

oh-my-posh init pwsh --config "~\AppData\Local\Programs\oh-my-posh\themes\paradox.omp.json" | Invoke-Expression

I'm new to this stuff. Tring to start coding. Found the doode from "dev as life" channel and going through his guide about fancy pwshell settings. Fascinating.

2023-04-06_12-53-33

ask-sup commented 1 year ago

Greetings. The problem persists up to this day. Basically, i've installed oh-my-posh from scoop and $evn:POSH_THEMES_PATH variable contains a wrong path. It misses one folder - "Program". As previously mentioned i've used a longer path from %AppData% entry point and it worked

oh-my-posh init pwsh --config "~\AppData\Local\Programs\oh-my-posh\themes\paradox.omp.json" | Invoke-Expression

I'm new to this stuff. Tring to start coding. Found the doode from "dev as life" channel and going through his guide about fancy pwshell settings. Fascinating.

2023-04-06_12-53-33

There IS definitely something funky going on with the pwshell paths. pwshell ignores the system env path.

2023-04-06_14-42-46

ask-sup commented 1 year ago

I guess i've found the source of this issue. It's in the initial install script. There is no "$env:HOME" variable anymore.

2023-04-06_15-05-01

I think i got it completely fixed by manually correcting the "POSH_PATH" environment variable in pwshell User scope by executing this command:

[Environment]::SetEnvironmentVariable('POSH_PATH', 'C:\Users\askela\AppData\Local\Programs\oh-my-posh', 'User')

2023-04-06_15-10-44

It had auto-corrected "POSH_THEMES_PATH" variable and my custom profile theme statement "$env:POSH_THEMES_PATH\paradox.omp.json" worked automatically after terminal restart as it should.

JanDeDobbeleer commented 1 year ago

@kennedy wait a minute, you're on a VERY old version. Please follow the upgrade guide because that's no longer supported at all.

sanjai0py commented 1 year ago

i changed the $PROFILE value to oh-my-posh init pwsh --config 'C:\Users\user\AppData\Local\Programs\oh-my-posh\themes\robbyrussell.omp.json' | Invoke-Expression and it worked

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