Feature Request - "pre" execution functionality
See original GitHub issueSummary of the new feature/enhancement
Ability to have a version of the prompt function that can run prior to each command being run in the command line & allow changing of the prompt within it
This would allow for example for a series of actions to set items in the prompt and host prior to execution (like when you kicked off a command, particularly any long running command)
Proposed technical implementation details (optional)
a mirroring of the prompt function but instead runs before the command issued at the terminal is actually run.
function preprompt {
Write-Host "[" -NoNewline
Write-Host (Get-Date -Format "HH:mm:ss") -ForegroundColor Gray -NoNewline
Write-Host "] [" -NoNewline
}
The above would on each execution update the prompt with the time that the command was executed at The same code used in the prompt function below update the prompt with the time that the command was completed at
function prompt {
Write-Host "[" -NoNewline
Write-Host (Get-Date -Format "HH:mm:ss") -ForegroundColor Gray -NoNewline
Write-Host "] [" -NoNewline
}
Having both is useful for transcriptions/interactive glances/ long running processes & would be a useful improvement to the engine
Issue Analytics
- State:
- Created 3 years ago
- Comments:9 (6 by maintainers)
Top GitHub Comments
The ask is a function to run before an accepted command line gets executed, so change the title to differentiate from #15104, which asks for a way to call custom functions before evaluating the ‘Prompt’ function.
That’s not impossible, but that would be a very challenging work item to make consistent. You’d have to keep track of exactly how much the prompt initially wrote, clear it, re-write it, and then force PSRL to re-render. Also every custom
PSHost
would have to copy that logic, asprompt
processing is currently left to the host. Add in how different terminal emulators process these types of escape sequences a little bit differently and it’s hard to imagine this being implemented consistently.I think the only feasible option transcript wise would be to just write the re-rendered prompt normally.