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

Write-VCSPrompt in background thread (sample implementation) #610

Open
cspotcode opened this issue Aug 28, 2018 · 2 comments
Open

Write-VCSPrompt in background thread (sample implementation) #610

cspotcode opened this issue Aug 28, 2018 · 2 comments

Comments

@cspotcode
Copy link

I just wanted to share this with the team; please feel free to close this issue. My work computer is kinda slow thanks to a corporate virus scanner. In particular, posh-git's Write-VCSStatus slows down my prompt, so I wanted to see if I could run it in a background thread. The result is messy, but it works!

It starts a worker thread in the background within which it loads posh-git. The prompt function sends a message to the worker thread asking it to run Write-VCSStatus. Powershell.OnIdle events are used to wait for the response and re-render the prompt via a call to PSReadline's API. Re-rendering doesn't affect text you've entered, so effectively you can keep working at the prompt and/or wait a second for git status to appear.

https://gist.github.com/cspotcode/f45c9d92412becbe9201c8de63e4ff98

System Details

  • posh-git version/path: 1.0.0-beta2
  • PowerShell version: Windows PowerShell 5.1.17134.112
  • Git version: 2.18.0.windows.1
  • Operating system name and version: Windows 10 v1803
@lzybkr
Copy link
Collaborator

lzybkr commented Aug 28, 2018

Great idea - this could be useful for folks working in large repos like Windows.

@dahlbyk
Copy link
Owner

dahlbyk commented Aug 28, 2018

This has been tried before (#51, #52, #104), but I'm not opposed to trying it again with newer APIs. Why don't you open a PR with your code enabled by something like $GitPromptSettings.AsyncPrompt = $true so folks can test it out more easily?

Out of curiosity, have you tried using https://github.com/cmarcusreid/git-status-cache-posh-client?

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

No branches or pull requests

4 participants