2019-10-15 15:10:16 +00:00
|
|
|
#!/usr/bin/env pwsh
|
|
|
|
|
|
|
|
# Starship assumes UTF-8
|
|
|
|
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
|
|
|
|
function global:prompt {
|
|
|
|
$out = $null
|
|
|
|
# @ makes sure the result is an array even if single or no values are returned
|
|
|
|
$jobs = @(Get-Job | Where-Object { $_.State -eq 'Running' }).Count
|
|
|
|
|
2020-04-30 08:40:56 +00:00
|
|
|
$env:PWD = $PWD
|
2020-08-20 04:45:10 +00:00
|
|
|
$current_directory = (Convert-Path -LiteralPath $PWD)
|
2020-04-30 08:40:56 +00:00
|
|
|
|
2019-10-15 15:10:16 +00:00
|
|
|
if ($lastCmd = Get-History -Count 1) {
|
2019-12-19 22:38:06 +00:00
|
|
|
$duration = [math]::Round(($lastCmd.EndExecutionTime - $lastCmd.StartExecutionTime).TotalMilliseconds)
|
2019-10-15 15:10:16 +00:00
|
|
|
# & ensures the path is interpreted as something to execute
|
2020-04-30 08:40:56 +00:00
|
|
|
$out = @(&::STARSHIP:: prompt "--path=$current_directory" --status=$lastexitcode --jobs=$jobs --cmd-duration=$duration)
|
2019-10-15 15:10:16 +00:00
|
|
|
} else {
|
2020-04-30 08:40:56 +00:00
|
|
|
$out = @(&::STARSHIP:: prompt "--path=$current_directory" --status=$lastexitcode --jobs=$jobs)
|
2019-10-15 15:10:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Convert stdout (array of lines) to expected return type string
|
|
|
|
# `n is an escaped newline
|
|
|
|
$out -join "`n"
|
|
|
|
}
|
|
|
|
|
|
|
|
$ENV:STARSHIP_SHELL = "powershell"
|