I like to include the Mercurial/Git repo status in my PowerShell prompt. Sometimes this slows down the prompt()
function considerably, causing a long wait until you can start typing in the shell. I'm wondering, is it possible to update the prompt async?
Ideally it would:
Write-Host
the current directory (typical prompt)prompt
hasn't been called again, insert the repo status into the prompt.Has anyone done this before?
Not per se.
You can't update the prompt asynchronously because the prompt just returns text, and it's called in a host whenever a top-level command is done.
You could rewrite prompt to do something like check a data source, or a variable which you update asynchronously. So the prompt wouldn't keep changing while the command is running, but it won't hang for a while because it will just be looking up data.
The more tricky thing of this is that it gets into the game of trying to peek at execution results after the fact. PowerShell doesn't keep them around unless they're assigned to something. So to do this right one must override Out-Default (which only works well in the ISE, PowerGUI, etc, not powershell.exe). Overriding this isn't so hard, but it requries knowing a lot of PowerShell voodoo, even by my impressive standards.
On the bright side, I've obviously been thinking this thru a lot, and have a module that does a lot of this, I'm just determining what I'm going to do with it and if it stays in its own module or joins one of the other modules we build.
I'll update this when out, but this roadmap should help considerably.
The short answer is that you cannot update the prompt async, but you can make it darn fast, and the tricks required to do so open up many cooler doors.
Hope this helps
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With