Closed dpokluda closed 2 months ago
I am experiencing the same issue. For me it also started to happen from version 21.23.3
In my case prompt theme is being fully reset when we try to override Function:Prompt (which worked perfectly before the update 21.23.3 and further updates).
$currentPrompt = Get-Content Function:Prompt
$currentPromptText = $currentPrompt.ToString()
$currentPromptText += "SOME CODE"
$newPrompt = [scriptblock]::Create($currentPromptText)
Set-Item -Path Function:prompt -Value $newPrompt -Force
Content of Function:Prompt
# store the orignal last command execution status
if ($global:NVS_ORIGINAL_LASTEXECUTIONSTATUS -is [bool]) {
# make it compatible with NVS auto-switching, if enabled
$script:OriginalLastExecutionStatus = $global:NVS_ORIGINAL_LASTEXECUTIONSTATUS
}
else {
$script:OriginalLastExecutionStatus = $?
}
# store the orignal last exit code
$script:OriginalLastExitCode = $global:LASTEXITCODE
Set-PoshPromptType
if ($script:PromptType -ne 'transient') {
Update-PoshErrorCode
}
$cleanPSWD = Get-CleanPSWD
$stackCount = global:Get-PoshStackCount
Set-PoshContext
$terminalWidth = Get-TerminalWidth
# set the cursor positions, they are zero based so align with other platforms
$env:POSH_CURSOR_LINE = $Host.UI.RawUI.CursorPosition.Y + 1
$env:POSH_CURSOR_COLUMN = $Host.UI.RawUI.CursorPosition.X + 1
$standardOut = Start-Utf8Process $script:OMPExecutable @("print", $script:PromptType, "--status=$script:ErrorCode", "--pswd=$cleanPSWD", "--execution-time=$script:ExecutionTime", "--stack-count=$stackCount", "--config=$env:POSH_THEME", "--shell-version=$script:PSVersion", "--terminal-width=$terminalWidth", "--shell=$script:ShellName", "--no-status=$script:NoExitCode")
# make sure PSReadLine knows if we have a multiline prompt
Set-PSReadLineOption -ExtraPromptLineCount (($standardOut | Measure-Object -Line).Lines - 1)
# The output can be multi-line, joining them ensures proper rendering.
$standardOut -join "`n"
# remove any posh-git status
$env:POSH_GIT_STATUS = $null
# restore the orignal last exit code
$global:LASTEXITCODE = $script:OriginalLastExitCode
I tested scenario when I updated Function:Prompt value without any changes, and theme resets in this case too.
$currentPrompt = Get-Content Function:Prompt
$currentPromptText = $currentPrompt.ToString()
$newPrompt = [scriptblock]::Create($currentPromptText)
Set-Item -Path Function:prompt -Value $newPrompt -Force
Maybe this information will be useful to debug
Reproduced on my end. We've done some changes related to the prompt function in PowerShell. Will try to fix it.
$currentPrompt = Get-Content Function:Prompt $currentPromptText = $currentPrompt.ToString() $currentPromptText += "SOME CODE" $newPrompt = [scriptblock]::Create($currentPromptText) Set-Item -Path Function:prompt -Value $newPrompt -Force
@nbdinara Are you sure the above code worked before? I tested it but it didn't even work (resulting in a fallback prompt PS>
) in v21.23.2. 🤔
@lewis-yeung , this is what I see:
v21.23.2 - theme is not being reset
v21.23.3 - theme is being reset
On screenshots above I execute function that has code I specified above (and you can see the function content on the screenshots as well). You can see that everything worked fine on version 21.23.2. On version 21.23.3 theme is being reset after function execution.
But it is interesting that if I run code line by line in console window instead of using function, theme is being reset even if the version of oh-my-posh is v21.23.2.
@nbdinara I still cannot get the example to work in v21.23.2, either in a function or running line by line. What's your PowerShell version?
@dpokluda @nbdinara What does the $error
variable hold when you have a broken prompt?
@nbdinara This should be a scope related issue. Many OMP functions called inside the prompt
function are defined in a module scope, thus cannot be called outside when running the above example. I'm curious why it works in v21.23.2 on your machine.
Name Value
---- -----
PSVersion 7.4.3
PSEdition Core
GitCommitId 7.4.3
OS Microsoft Windows 10.0.22631
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
ErrorRecord : The term 'Set-PoshPromptType' 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.
CommandName : Set-PoshPromptType
WasThrownFromThrowStatement : False
TargetSite : System.Collections.ObjectModel.Collection`1[System.Management.Automation.PSObject]
Invoke(System.Collections.IEnumerable)
Message : The term 'Set-PoshPromptType' 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.
Data : {[System.Management.Automation.Interpreter.InterpretedFrameInfo,
System.Management.Automation.Interpreter.InterpretedFrameInfo[]]}
InnerException :
HelpLink :
Source : System.Management.Automation
HResult : -2146233087
StackTrace : at System.Management.Automation.Runspaces.PipelineBase.Invoke(IEnumerable input)
at Microsoft.PowerShell.Executor.ExecuteCommandHelper(Pipeline tempPipeline,
Exception& exceptionThrown, ExecutionOptions options)
Set-PoshPromptType:
Line |
13 | Set-PoshPromptType
| ~~~~~~~~~~~~~~~~~~
| The term 'Set-PoshPromptType' 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.
Test-Path: Value cannot be null. (Parameter 'The provided Path argument was null or an empty collection.')
Got the same error on PowerShell v7.4.3:
The term 'Set-PoshPromptType' is not recognized as a name of a cmdlet, function, script file, or executable program.
@nbdinara If you would like to wrap the prompt
function, it's better to write something like:
$originalPromptFunction = $Function:prompt
function prompt {
$originalOutput = $originalPromptFunction.Invoke()
# Some code...
}
@nbdinara I had a few debug runs here and it's safe to say this isn't supported. There are so many side effects here when hijacking the prompt function, if you want to display additional text it's better to override Set-PoshContext
to add specific, non built-in context instead of hacking the prompt yourself (see here for more information). That will always have challenges. Even when we export every function, it still breaks. I also can't make that work on older version as it is indeed a scope issue, something that wasn't introduced in that version but way back.
Code of Conduct
What happened?
Today, after installing latest version of oh-my-posh, I don't see my prompt being rendered (only
PS>
). I have tried multiple versions, and it seems to start since 21.23.3 (it works with 21.23.2 but no version after). I tried to search for similar issues but didn't find anything relevant.I am not sure if my custom theme contains anything special that is no longer supported but the version 21.23.3 doesn't talk about deprecating any previous feature.
When comparing
debug
output from 21.23.2 to newer version, I am noticing some changes but nothing that would clearly explain what is wrong (not working) in the current version.Theme
What OS are you seeing the problem on?
Windows
Which shell are you using?
powershell
Log output