Skip to content

Instantly share code, notes, and snippets.

@zooba
Last active May 21, 2020 21:52
Show Gist options
  • Save zooba/1b45555945ce3a466643dbbdbdbf76e7 to your computer and use it in GitHub Desktop.
Save zooba/1b45555945ce3a466643dbbdbdbf76e7 to your computer and use it in GitHub Desktop.
Powershell title updater
function Prompt {
$p = Get-Location
while ($p) {
if (Test-Path "$p\.git") { break }
if (Test-Path "$p\pyproject.toml") { break }
if (Test-Path "$p\setup.py") { break }
$p = Split-Path -Parent $p
}
if ($p) {
$n1 = Split-Path -Leaf $p
$n2 = Split-Path -Leaf (Get-Location)
if ($n1 -ne $n2) {
$host.ui.RawUI.WindowTitle = "<$n1>\$n2 - Powershell"
} else {
$host.ui.RawUI.WindowTitle = "<$n1> - Powershell"
}
} else {
$p = Get-Location
$n1 = Split-Path -Leaf $p
$p = Split-Path -Parent $p
while ($p -and ($n1.Length -lt 16)) {
$n1 = Join-Path (Split-Path -Leaf $p) $n1
$p = Split-Path -Parent $p
}
$n2 = Get-Location
if ($n1 -ne $n2) {
$host.ui.RawUI.WindowTitle = "...\$n1 ($n2) - Powershell"
} else {
$host.ui.RawUI.WindowTitle = "$n1 - Powershell"
}
}
return "$(Get-Location)> "
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment