Last active
May 21, 2020 21:52
-
-
Save zooba/1b45555945ce3a466643dbbdbdbf76e7 to your computer and use it in GitHub Desktop.
Powershell title updater
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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