Last active
September 9, 2024 03:51
-
-
Save 1nVitr0/486b238a1e9a361dd0a2f6fc92f86d4f to your computer and use it in GitHub Desktop.
Powershell - pretty shortened prompt
This file contains hidden or 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
$SHORTENED_DIRS = [PSCustomObject]@{ | |
'A:'='A';'B:'='B';'C:'='C';'D:'='D';'E:'='E';'F:'='F';'G:'='G';'H:'='H';'I:'='I';'J:'='J';'K:'='K';'L:'='L';'M:'='M'; | |
'N:'='N';'O:'='O';'P:'='P';'Q:'='Q';'R:'='R';'S:'='S';'T:'='T';'U:'='U';'V:'='V';'W:'='W';'X:'='X';'Y:'='Y';'Z:'='Z' | |
AppData='AppData' | |
Documents='Docs' | |
projects='proj' | |
Images='Imgs' | |
Downloads='Dwnlds' | |
Pictures='Pics' | |
Videos='Vids' | |
Users='Usrs' | |
OneDrive='Drv' | |
personal='pers' | |
vscode='vsc' | |
extensions='exts' | |
'Program Files'='Prgrms' | |
'Program Files (x86)'='Prgrmsx86' | |
'Program Data'='PrgrmDat' | |
Windows='Win' | |
} | |
$HOMEDRIVE = $env:HOMEDRIVE | |
$SHORTENED_DIRS."$HOMEDRIVE" = '' | |
Function Get-ShortenedPath {param([string]$prop,[boolean]$long) | |
$shrt = $SHORTENED_DIRS."$prop" | |
If ($shrt -ne $null) {$shrt} | |
ElseIf ($long) {@($prop[0];$prop.Substring(1).ToCharArray() | %{if($_ -notlike "[aeiou]") {$_}}) -join ''} | |
Else {$prop[0]} | |
} | |
Function prompt { | |
$pre = $((''+$PWD.Path).replace($HOME, '~')) | |
$dirs = $pre.Split("\") | |
$shrt = @($dirs | %{$i=1}{ | |
If ($i -eq $dirs.Length) {"$_"} | |
ElseIf ($dirs.Length -le 4) {"$_"} | |
Else {Get-ShortenedPath "$_" ($i -eq ($dirs.Length-1))} | |
$i++ | |
}) | |
$prmpt = $shrt -join "\" | |
"$ $prmpt > " | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment