1
0
mirror of https://github.com/Llewellynvdm/starship.git synced 2024-11-28 07:46:28 +00:00

feat: Add starship_precmd_user_func support for PowerShell. (#3115)

This commit is contained in:
Michael J. Ryan 2021-10-07 11:08:31 -07:00 committed by GitHub
parent 9f2f5293e3
commit 94d7de7f4e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 0 deletions

View File

@ -42,6 +42,21 @@ trap blastoff DEBUG # Trap DEBUG *before* running starship
eval $(starship init bash)
```
## Custom pre-prompt and pre-execution Commands in PowerShell
PowerShell does not have a formal preexec/precmd framework like most other shells.
Because of this, it is difficult to provide fully customizable hooks in `powershell`.
However, Starship does give you limited ability to insert your own functions
into the prompt-rendering procedure:
Create a function named `Invoke-Starship-PreCommand`
```powershell
function Invoke-Starship-PreCommand {
$host.ui.Write("🚀")
}
```
## Change Window Title
Some shell prompts will automatically change the window title for you (e.g. to
@ -85,6 +100,17 @@ function set_win_title(){
starship_precmd_user_func="set_win_title"
```
You can also set a similar output with PowerShell by creating a function named `Invoke-Starship-PreCommand`.
```powershell
# edit $PROFILE
function Invoke-Starship-PreCommand {
$host.ui.Write("`e]0; PS> $env:USERNAME@$env:COMPUTERNAME`: $pwd `a")
}
Invoke-Expression (&starship init powershell)
```
## Enable Right Prompt
Some shells support a right prompt which renders on the same line as the input. Starship can

View File

@ -63,6 +63,13 @@ function global:prompt {
$process.StandardOutput.ReadToEnd();
}
# Invoke precmd, if specified
try {
if (Test-Path function:Invoke-Starship-PreCommand) {
Invoke-Starship-PreCommand
}
} catch {}
$origDollarQuestion = $global:?
$origLastExitCode = $global:LASTEXITCODE