Skip to content

Instantly share code, notes, and snippets.

@squaresmile
Last active February 25, 2021 03:07
Show Gist options
  • Save squaresmile/399a24209671788ba0ab850b148577a4 to your computer and use it in GitHub Desktop.
Save squaresmile/399a24209671788ba0ab850b148577a4 to your computer and use it in GitHub Desktop.
Powershell profile
function Prompt {
$loc = Get-Location
$title = $($loc.Drive.Root)
([uri]$loc.Path).segments | Select-Object -Skip 2 | Select-Object -SkipLast 1 | ForEach-Object {
$title = $title + $_.Substring(0, 1) + "\"
}
$leaf = $(Split-Path $loc.Path -Leaf)
# If the path is just the drive C:\ the leaf = title = C:\
if ($title -ne $leaf) {
$title = $title + $leaf
}
$Host.UI.RawUI.WindowTitle = $title
"PS " + $title + "> "
}
@squaresmile
Copy link
Author

Example: Full working directory C:\Users\squaresmile\github\powershell -> C:\U\s\g\powershell.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment