Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refresh Git widgets periodically #5036

Open
1 task done
Darker21 opened this issue Jun 10, 2024 · 8 comments
Open
1 task done

Refresh Git widgets periodically #5036

Darker21 opened this issue Jun 10, 2024 · 8 comments
Assignees
Labels
🚀 feat New feature

Comments

@Darker21
Copy link

Code of Conduct

  • I agree to follow this project's Code of Conduct

What would you like to see changed/added?

Was wondering if it would be possible to update the git widgets details automatically rather than having to enter a new line to refresh the state shown on the widgets (i.e. file changes, incoming changes, outgoing commits).

Not sure if this is 100% possible but would be a nice feature to have for people like myself using the terminal in IDE's such as VS Code who prefer the terminal to the extensions for git

@JanDeDobbeleer
Copy link
Owner

@Darker21 by automatically, do you mean on an interval? There's no way to reload only the git part, as the prompt is a string. We could however reload the prompt on an interval in case it wasn't reloaded on for a predefined timeout. This would only work for shells that have a way to reload the prompt, which is a few I believe. What shell do you use? I might be able to craft something that work together with you before adding that to our shell scripts and configuration.

@Darker21
Copy link
Author

An interval was what I had in mind, I'm using PowerShell within Windows Terminal.
I could be missing some config if it already exists

@JanDeDobbeleer
Copy link
Owner

JanDeDobbeleer commented Jun 10, 2024

@Darker21 you could try adding this logic AFTER initialising oh-my-posh, this wasn't tested yet as I'm not on my laptop ATM.

# Create a timer object with a specific interval and a starttime
$timer = New-Object -Type Timers.Timer
$timer.Interval  = 3000 # milliseconds, in this case 3 seconds

# Register an event for every passed interval
Register-ObjectEvent -InputObject $timer  -EventName Elapsed  -SourceIdentifier "Timer.Elapsed" -Action {
    
    # reload the prompt using PSReadLine
    [Microsoft.PowerShell.PSConsoleReadLine]::InvokePrompt()

} | Out-Null

function Start-Timer {
    # stop the timer when it's running
    if ($timer.Enabled) {
        $timer.Stop()
    }

    # Start the timer
    $timer.Start()
}

New-Alias -Name 'Set-PoshContext' -Value 'Start-Timer' -Scope Global -Force

@Darker21
Copy link
Author

That's what I was looking for, it's working as expected, thanks for that

@JanDeDobbeleer
Copy link
Owner

@Darker21 I might add this natively so I'm leaving this open in the meantime. Or maybe the snippet helps someone do a contribution. It's a cool feature to have. No stale prompts.

@Darker21
Copy link
Author

Darker21 commented Jun 10, 2024

I think it would be a good addition and could open up possibilities for other prompt options such as the Spotify one currently (#4732) open to 'refresh' and provide 'real time' updates

@Kyren223
Copy link

@Darker21 I might add this natively so I'm leaving this open in the meantime. Or maybe the snippet helps someone do a contribution. It's a cool feature to have. No stale prompts.

Hello, I need this exact feature (be able to set a reload interval in ms), for a different purpose
I was able to export an env var with my shell's vi-mode, but it doesn't update it, unless I press enter for a new command.

I am using zsh as my shell, I am not sure how to reload oh-my-posh, I tried zle reset-prompt and zle && zle reset-prompt but they don't seem to work.

Would love this as a feature, but in the meantime, if you can please provide me with a script/command to reload oh-my-posh, that'd be great

@rliberoff
Copy link

It’s interesting. For some reason, on my PC, the command line blinks instead of refreshing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🚀 feat New feature
Projects
None yet
Development

No branches or pull requests

4 participants