Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@1nVitr0
Last active April 10, 2022 21:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 1nVitr0/486b238a1e9a361dd0a2f6fc92f86d4f to your computer and use it in GitHub Desktop.
Save 1nVitr0/486b238a1e9a361dd0a2f6fc92f86d4f to your computer and use it in GitHub Desktop.
Powershell - pretty shortened prompt
$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