JanDeDobbeleer / oh-my-posh

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

Theme not loading when new Powershell tab is opened #1485

Closed mwasowski closed 2 years ago

mwasowski commented 2 years ago

Code of Conduct

What happened?

I am having issue when I open Windows Terminal with either Powershell Core or Windows Powershell. The theme is not loading nad I am presented with the default one: obraz I have both configured in $profile and it was working before the update I did today. What is strange when I launch . $profile it correctly sets my theme.

Theme

powerlevel10k_rainbow with minor modifications

What OS are you seeing the problem on?

Windows

Which shell are you using?

powershell

Log output

Version: 6.38.2

Segments:

ConsoleTitle(true) -   0 ms -
session(true)  -   0 ms -  * 
path(true)     -   0 ms -   ~ 
git(false)     -   9 ms -
battery(false) -   1 ms -
node(false)    -   0 ms -
shell(true)    -   0 ms -  ﲵ uni 
root(false)    -   0 ms -
text(true)     -   0 ms -  NO CONFIG 
exit(true)     -   0 ms -   

Run duration: 12.1987ms

Logs:

2021/12/22 16:40:22 debug: getenv
C:\Users\*\AppData\Local
2021/12/22 16:40:22 getenv duration: 0s, args: LOCALAPPDATA
2021/12/22 16:40:22 getCachePath duration: 0s, args:
2021/12/22 16:40:22 getArgs duration: 0s, args:
2021/12/22 16:40:22 getArgs duration: 0s, args:
2021/12/22 16:40:22 getShellName duration: 0s, args:
2021/12/22 16:40:22 debug: getenv

2021/12/22 16:40:22 getenv duration: 0s, args: OMP_CACHE_DISABLED
2021/12/22 16:40:22 isRunningAsRoot duration: 0s, args:
2021/12/22 16:40:22 getcwd duration: 0s, args:
2021/12/22 16:40:22 getPathSeperator duration: 0s, args:
2021/12/22 16:40:22 getPathSeperator duration: 0s, args:
2021/12/22 16:40:22 getShellName duration: 0s, args:
2021/12/22 16:40:22 getCurrentUser duration: 0s, args:
2021/12/22 16:40:22 getHostName duration: 0s, args:
2021/12/22 16:40:22 getcwd duration: 0s, args:
2021/12/22 16:40:22 debug: getenv

2021/12/22 16:40:22 getenv duration: 0s, args: SSH_CONNECTION
2021/12/22 16:40:22 debug: getenv

2021/12/22 16:40:22 getenv duration: 0s, args: SSH_CLIENT
2021/12/22 16:40:22 getCurrentUser duration: 0s, args:
2021/12/22 16:40:22 getRuntimeGOOS duration: 0s, args:
2021/12/22 16:40:22 getHostName duration: 0s, args:
2021/12/22 16:40:22 debug: getenv
*
2021/12/22 16:40:22 getenv duration: 0s, args: POSH_SESSION_DEFAULT_USER
2021/12/22 16:40:22 getcwd duration: 0s, args:
2021/12/22 16:40:22 getcwd duration: 0s, args:
2021/12/22 16:40:22 getArgs duration: 0s, args:
2021/12/22 16:40:22 getcwd duration: 0s, args:
2021/12/22 16:40:22 getRuntimeGOOS duration: 0s, args:
2021/12/22 16:40:22 getRuntimeGOOS duration: 0s, args:
2021/12/22 16:40:22 getPathSeperator duration: 0s, args:
2021/12/22 16:40:22 getPathSeperator duration: 0s, args:
2021/12/22 16:40:22 getPathSeperator duration: 0s, args:
2021/12/22 16:40:22 getRuntimeGOOS duration: 0s, args:
2021/12/22 16:40:22 stackCount duration: 0s, args:
2021/12/22 16:40:22 getcwd duration: 0s, args:
2021/12/22 16:40:22 getRuntimeGOOS duration: 0s, args:
2021/12/22 16:40:22 hasCommand duration: 9.5085ms, args: git.exe
2021/12/22 16:40:22 getcwd duration: 0s, args:
2021/12/22 16:40:22 error: hasParentFilePath
CreateFile C:\.git: The system cannot find the file specified.
2021/12/22 16:40:22 hasParentFilePath duration: 0s, args: .git
2021/12/22 16:40:22 getcwd duration: 0s, args:
2021/12/22 16:40:22 getBatteryInfo duration: 1.5932ms, args:
2021/12/22 16:40:22 getcwd duration: 0s, args:
2021/12/22 16:40:22 getcwd duration: 0s, args:
2021/12/22 16:40:22 getcwd duration: 0s, args:
2021/12/22 16:40:22 getShellName duration: 0s, args:
2021/12/22 16:40:22 getcwd duration: 0s, args:
2021/12/22 16:40:22 isRunningAsRoot duration: 0s, args:
2021/12/22 16:40:22 getcwd duration: 0s, args:
2021/12/22 16:40:22 isRunningAsRoot duration: 0s, args:
2021/12/22 16:40:22 getcwd duration: 0s, args:
2021/12/22 16:40:22 getPathSeperator duration: 0s, args:
2021/12/22 16:40:22 getPathSeperator duration: 0s, args:
2021/12/22 16:40:22 getShellName duration: 0s, args:
2021/12/22 16:40:22 getCurrentUser duration: 0s, args:
2021/12/22 16:40:22 getHostName duration: 0s, args:
2021/12/22 16:40:22 getcwd duration: 0s, args:
2021/12/22 16:40:22 lastErrorCode duration: 0s, args:
mwasowski commented 2 years ago

Did I miss another configuration change in one of the updates? :)

JanDeDobbeleer commented 2 years ago

@mwasowski what does your profile look like?

mwasowski commented 2 years ago
using namespace System.Management.Automation
using namespace System.Management.Automation.Language

$env:POSH_SESSION_DEFAULT_USER  = [System.Environment]::UserName

# Import-Module posh-git
Import-Module oh-my-posh
Import-Module PSReadLine

function upmod { Get-InstalledModule | Update-Module }

Set-PoshPrompt -Theme ~\.oh-my-posh\.powerlevel10k_rainbow.omp.json

Enable-PoshTransientPrompt

Clear-Host

# Shows navigable menu of all options when hitting Tab
Set-PSReadlineKeyHandler -Key Tab -Function MenuComplete

# Autocompletion for arrow keys
Set-PSReadLineOption -HistorySearchCursorMovesToEnd
Set-PSReadLineKeyHandler -Key UpArrow -Function HistorySearchBackward
Set-PSReadLineKeyHandler -Key DownArrow -Function HistorySearchForward
JanDeDobbeleer commented 2 years ago

@mwasowski what happens when you change

Set-PoshPrompt -Theme ~\.oh-my-posh\.powerlevel10k_rainbow.omp.json 

for

oh-my-posh --init --shell pwsh --config ~\.oh-my-posh\.powerlevel10k_rainbow.omp.json | Invoke-Expression
mwasowski commented 2 years ago

Interesting..that actually works. Just it feels like it's taking longer? 🤔

Also with my initial config, if I do

. $profile

It loads the theme correctly. It's like it's unable to do it on the initial open.

JanDeDobbeleer commented 2 years ago

@mwasowski can't take longer to load as the first cmdlet is a wrapper around that one :-)

mwasowski commented 2 years ago

That's why I wrote that it feels like it takes longer ;)

mwasowski commented 2 years ago

Interesting. When I did this in my config:

Set-PoshPrompt -Theme ~\.oh-my-posh\.powerlevel10k_rainbow.omp.json
Set-PoshPrompt -Theme ~\.oh-my-posh\.powerlevel10k_rainbow.omp.json

It also works ;)

JanDeDobbeleer commented 2 years ago

@mwasowski zero sense was made but I'll try to see what's going on 😀

mwasowski commented 2 years ago

@JanDeDobbeleer Yeah, I know! It's like it is not initializing correctly? I think this is not that urgent and now I bite myself I bothered you by opening this before Christmas 😦

JanDeDobbeleer commented 2 years ago

@mwasowski I tried to reproduce this but I can't... It always loads first try. I would resort to only using the invoke syntax:

oh-my-posh --init --shell pwsh --config ~\.oh-my-posh\.powerlevel10k_rainbow.omp.json | Invoke-Expression

The Set-PoshPrompt command is silently deprecated.

BenjaminAbt commented 2 years ago

Looks like I have the same issue (or at least a side effect) on a fresh install of Windows 10

Does not work anymore:

oh-my-posh --init --shell pwsh --config ~\.oh-my-posh\.unicorn.omp.json  | Invoke-Expression

Works great:

Set-PoshPrompt Unicorn

Env:

It looks like oh-my-posh --init --shell pwsh --config ~\AppData\Local\Programs\oh-my-posh\themes\unicorn.omp.json | Invoke-Expression is working for me (now).

JanDeDobbeleer commented 2 years ago

Does not work anymore:

oh-my-posh --init --shell pwsh --config ~\.oh-my-posh\.unicorn.omp.json  | Invoke-Expression

@BenjaminAbt but is that theme located there?

akshay-zz commented 2 years ago

Hi I was also facing this. Today only I setup the oh-my-posh.

When I was trying to change the them by below command nothing was happening. Btw this command is working for the first time. Also one behavior I found , It doesn't matter which theme you are selecting it will by default applying jandedobbeleer.omp.json theme for me. oh-my-posh --init --shell pwsh --config ~\.oh-my-posh\.unicorn.omp.json | Invoke-Expression

As soon I tried the following command it worked for me

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

@JanDeDobbeleer @BenjaminAbt

BenjaminAbt commented 2 years ago

@BenjaminAbt but is that theme located there?

Sorry! Obviously lost in the wave of notifications. Yes, the file was there.

In the meantime I moved the file to a new location. It can be loaded again.

oh-my-posh --init --shell pwsh --config $Env:OneDriveConsumer\Apps\OhMyPosh\abt.omp.json | Invoke-Expression
llysyganicz commented 2 years ago

Hi. I have the same issue.

I keep my config in home directory which is C:\Users\Łukasz. It contains letter from polish alphabet. Reloading profile or executing init once more loads theme correctly. I moved my theme to different location (without polish letter) and it works now.

posthumz commented 2 years ago

I am having the same issue and I think this may be a problem with the codepage. I got this problem whenever the path to my theme contains some non-ASCII character. With out setting any module my console is in codepage 936, by setting my theme with a non-ASCII path the it automatically uses the default theme and the codepage changes to 65001. Setting the theme the again under codepage 65001 works. (This may explain why setting it twice works) 图片

Alternatively, doing

chcp 65001
Set-PoshPrompt path_to_theme

in the $Profile works for me.

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