Thanks to PSReadLine's events, it is not hard to write a PowerShell command that can generate and inject text into the next command prompt, allowing you to edit it and run it.
There is something like this in the ReadLine AI project, and since someone asked how to do it on Mastodon, I thought I'd distill it here.
The scary version is to prepare the text in a variable (e.g. $Suggestion
) and then register a handler for OnIdle
so that when the prompt finishes rendering, your text will be injected for the user to run.
The version in ReadLine AI actually registers a hotkey instead, which allows it to read what you've written so far, get a completion, and then update the current command, instead of the next command.