JanDeDobbeleer / oh-my-posh

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

transient prompt doesn't work on first load #3304

Closed dcnieho closed 1 year ago

dcnieho commented 1 year ago

Code of Conduct

What happened?

The transient prompt doesn't work in a new session, only when i reload oh-my-posh does it start working. See video:

https://user-images.githubusercontent.com/1787673/210380748-4783eb1a-19c4-45cd-b9be-3548e5e625fd.mp4

Theme

{
  "$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json",
  "console_title_template": "{{ if .Root }}(root) {{ end }}{{ .Shell }} @ {{ .Folder }}",
  "blocks": [
    {
      "type": "prompt",
      "alignment": "left",
      "segments": [
        {
          "type": "os",
          "background": "darkGray",
          "foreground": "lightWhite",
          "style": "diamond",
          "leading_diamond": "\ue0b2",
          "properties": {
            "alpine": "\uf300",
            "arch": "\uf303",
            "centos": "\uf304",
            "debian": "\uf306",
            "elementary": "\uf309",
            "fedora": "\uf30a",
            "gentoo": "\uf30d",
            "linux": "\ue712",
            "macos": "\ue711",
            "manjaro": "\uf312",
            "mint": "\uf30f",
            "opensuse": "\uf314",
            "raspbian": "\uf315",
            "ubuntu": "\uf31c",
            "windows": "\ue70f"
          },
          "template": " {{ if .WSL }}\ue712 on {{ end }}{{ .Icon }} "
        },
        {
          "type": "session",
          "background": "green",
          "background_templates": [
              "{{ if .Root }}lightRed{{ end }}"
            ],
          "foreground": "black",
          "style": "powerline",
          "powerline_symbol": "\ue0b0",
          "template": " {{ .UserName }} "
        }
      ]
    }
  ],
  "transient_prompt": {
    "template": "transient> "
  },
  "osc99": true,
  "version": 2
}

relevant part of $PROFILE:

if ($host.Name -eq 'ConsoleHost')
{
    Import-Module PSReadLine
}

# installs module if import fails
function ImportOrInstallModule([string[]]$module) {
    Import-Module -Global $module -ErrorAction SilentlyContinue ||
    Install-Module -Name $module -Scope CurrentUser -Repository PSGallery -Force &&
    Import-Module -Global $module
}

function InstallModuleIfNeeded([string[]]$module) {
    $e = Get-InstalledModule $module -ErrorAction SilentlyContinue
    if (-not $e) {
        Install-Module -Name $module -Scope CurrentUser -SkipPublisherCheck -Force
    }
}

## install requirements and import them:
ImportOrInstallModule 'CompletionPredictor'
ImportOrInstallModule 'Terminal-Icons'
ImportOrInstallModule 'posh-git'
InstallModuleIfNeeded 'Microsoft.PowerShell.ConsoleGuiTools'

$GitPromptSettings.EnableStashStatus = $true    # needed so that oh my posh can get stash count
$configPath = Join-Path -Path (Split-Path $PROFILE -Parent) -ChildPath "thewickedd.omp.json"
oh-my-posh init pwsh --config $configPath | Invoke-Expression
$env:POSH_GIT_ENABLED = $true
$env:VIRTUAL_ENV_DISABLE_PROMPT = 1 # stop python venv activate from changing prompt

Set-PSReadLineOption -PredictionSource HistoryAndPlugin
Set-PSReadLineOption -PredictionViewStyle InlineView    # press F2 to bring up menu
Set-PSReadLineOption -EditMode Windows

What OS are you seeing the problem on?

Windows

Which shell are you using?

powershell

Log output

Version: 12.34.5

Segments:

ConsoleTitle(true) -   0 ms - (root) pwsh @ huml-dkn
os(true)       -   0 ms -  
session(true)  -   0 ms -  huml-dkn

Run duration: 10.745ms

Cache path: C:\Users\huml-dkn\AppData\Local\oh-my-posh

Config path: C:\Users\huml-dkn\Documents\PowerShell\thewickedd.omp.json

Logs:

2023/01/03 15:52:53 Getenv
C:\Users\huml-dkn\AppData\Local
2023/01/03 15:52:53 Getenv: 0s, args: LOCALAPPDATA
2023/01/03 15:52:53 CachePath: 0s
2023/01/03 15:52:53 Getenv
C:\Users\huml-dkn\Documents\PowerShell\thewickedd.omp.json
2023/01/03 15:52:53 Getenv: 520.9µs, args: POSH_THEME
2023/01/03 15:52:53 Shell
process name: pwsh.exe
2023/01/03 15:52:53 Shell: 7.3867ms
2023/01/03 15:52:53 resolveConfigPath: 7.9076ms
2023/01/03 15:52:53 Init: 9.0138ms
2023/01/03 15:52:53 Flags: 0s
2023/01/03 15:52:53 config.loadConfig: 603.9µs
2023/01/03 15:52:53 Flags: 0s
2023/01/03 15:52:53 Getenv

2023/01/03 15:52:53 Getenv: 0s, args: OMP_CACHE_DISABLED
2023/01/03 15:52:53 WindowsRegistryKeyValue: 0s, args: HKEY_CURRENT_USER\Software\Microsoft\Windows\DWM\ColorizationColor
2023/01/03 15:52:53 GOOS: 0s
2023/01/03 15:52:53 GOOS: 0s
2023/01/03 15:52:53 GOOS: 0s
2023/01/03 15:52:53 GOOS: 0s
2023/01/03 15:52:53 GOOS: 0s
2023/01/03 15:52:53 GOOS: 0s
2023/01/03 15:52:53 GOOS: 0s
2023/01/03 15:52:53 GOOS: 0s
2023/01/03 15:52:53 GOOS: 0s
2023/01/03 15:52:53 GOOS: 0s
2023/01/03 15:52:53 GOOS: 0s
2023/01/03 15:52:53 GOOS: 0s
2023/01/03 15:52:53 GOOS: 0s
2023/01/03 15:52:53 GOOS: 0s
2023/01/03 15:52:53 GOOS: 0s
2023/01/03 15:52:53 GOOS: 0s
2023/01/03 15:52:53 GOOS: 0s
2023/01/03 15:52:53 GOOS: 0s
2023/01/03 15:52:53 GOOS: 0s
2023/01/03 15:52:53 WindowsRegistryKeyValue
ColorizationColor(DWORD): 0xC4DA3B01
2023/01/03 15:52:53 Root: 0s
2023/01/03 15:52:53 Shell: 0s
2023/01/03 15:52:53 ErrorCode: 0s
2023/01/03 15:52:53 IsWsl: 0s
2023/01/03 15:52:53 GOOS: 0s
2023/01/03 15:52:53 Pwd
C:\Users\huml-dkn
2023/01/03 15:52:53 Pwd: 0s
2023/01/03 15:52:53 Home
C:\Users\huml-dkn
2023/01/03 15:52:53 GOOS: 0s
2023/01/03 15:52:53 GOOS: 0s
2023/01/03 15:52:53 GOOS: 0s
2023/01/03 15:52:53 GOOS: 0s
2023/01/03 15:52:53 GOOS: 0s
2023/01/03 15:52:53 GOOS: 0s
2023/01/03 15:52:53 GOOS: 0s
2023/01/03 15:52:53 GOOS: 0s
2023/01/03 15:52:53 GOOS: 0s
2023/01/03 15:52:53 GOOS: 0s
2023/01/03 15:52:53 GOOS: 0s
2023/01/03 15:52:53 User
huml-dkn
2023/01/03 15:52:53 User: 0s
2023/01/03 15:52:53 Host
HUML-DKN
2023/01/03 15:52:53 Host: 0s
2023/01/03 15:52:53 GOOS: 0s
2023/01/03 15:52:53 TemplateCache: 0s
2023/01/03 15:52:53 Flags: 0s
2023/01/03 15:52:53 Pwd
C:\Users\huml-dkn
2023/01/03 15:52:53 Pwd: 0s
2023/01/03 15:52:53 Home
C:\Users\huml-dkn
2023/01/03 15:52:53 GOOS: 0s
2023/01/03 15:52:53 GOOS: 0s
2023/01/03 15:52:53 TemplateCache: 0s
2023/01/03 15:52:53 TemplateCache: 0s
2023/01/03 15:52:53 Shell: 0s
2023/01/03 15:52:53 Pwd
C:\Users\huml-dkn
2023/01/03 15:52:53 Pwd: 0s
2023/01/03 15:52:53 Home
C:\Users\huml-dkn
2023/01/03 15:52:53 GOOS: 0s
2023/01/03 15:52:53 Getenv

2023/01/03 15:52:53 Getenv: 0s, args: SSH_CONNECTION
2023/01/03 15:52:53 Getenv

2023/01/03 15:52:53 Getenv: 0s, args: SSH_CLIENT
2023/01/03 15:52:53 TemplateCache: 0s
2023/01/03 15:52:53 TemplateCache: 0s
2023/01/03 15:52:53 Shell: 0s
2023/01/03 15:52:53 TemplateCache: 0s
2023/01/03 15:52:53 Getenv
C:\Users\huml-dkn\AppData\Local
2023/01/03 15:52:53 Getenv: 0s, args: LOCALAPPDATA
2023/01/03 15:52:53 CachePath: 0s
2023/01/03 15:52:53 Flags: 0s
JanDeDobbeleer commented 1 year ago

@dcnieho the transient prompt isn't compatible with Set-PSReadLineOption -EditMode Windows. Why that's the case, I don't know but commenting out that part gives the correct behaviour.

You have to move that line up, otherwise PSReadLine overrides our handler.

dcnieho commented 1 year ago

Yes, moving that line did the trick! Nice.

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