feat: Add starship_precmd_user_func support for PowerShell. (#3115)
This commit is contained in:
parent
9f2f5293e3
commit
94d7de7f4e
|
@ -42,6 +42,21 @@ trap blastoff DEBUG # Trap DEBUG *before* running starship
|
||||||
eval $(starship init bash)
|
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
|
## Change Window Title
|
||||||
|
|
||||||
Some shell prompts will automatically change the window title for you (e.g. to
|
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"
|
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
|
## Enable Right Prompt
|
||||||
|
|
||||||
Some shells support a right prompt which renders on the same line as the input. Starship can
|
Some shells support a right prompt which renders on the same line as the input. Starship can
|
||||||
|
|
|
@ -63,6 +63,13 @@ function global:prompt {
|
||||||
$process.StandardOutput.ReadToEnd();
|
$process.StandardOutput.ReadToEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Invoke precmd, if specified
|
||||||
|
try {
|
||||||
|
if (Test-Path function:Invoke-Starship-PreCommand) {
|
||||||
|
Invoke-Starship-PreCommand
|
||||||
|
}
|
||||||
|
} catch {}
|
||||||
|
|
||||||
$origDollarQuestion = $global:?
|
$origDollarQuestion = $global:?
|
||||||
$origLastExitCode = $global:LASTEXITCODE
|
$origLastExitCode = $global:LASTEXITCODE
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue