Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class CustomPromptPath {
- static [bool]PathEquals([System.IO.DirectoryInfo]$a, [System.IO.DirectoryInfo]$b) {
- return $a.FullName.Equals($b.FullName, 'OrdinalIgnoreCase')
- }
- static [String]GetCustomPromptPath([String]$homePath, [String]$currentPath) {
- $homeItem = Get-Item $homePath
- $current = Get-Item $currentPath
- $stack = New-Object 'System.Collections.Generic.Stack[string]'
- while ($null -ne $current) {
- if ([CustomPromptPath]::PathEquals($current, $homeItem)) {
- $stack.Push('~')
- $current = $null
- continue
- }
- if ($stack.Count -eq 0 -or $null -eq $current.Parent) { $stack.Push($current.Name) }
- else { $stack.Push($current.Name[0]) }
- $current = $current.Parent
- }
- $builder = New-Object 'System.Text.StringBuilder'
- while ($stack.Count -gt 0) {
- if ($builder.Length -gt 0 -and $builder[$builder.Length - 1] -ne '\') { $builder.Append('\') }
- $builder.Append($stack.Pop())
- }
- return $builder.ToString()
- }
- }
- function prompt {
- Write-Host $([CustomPromptPath]::GetCustomPromptPath($HOME, $PWD)) -ForegroundColor Yellow -NoNewline
- return " > "
- }
Add Comment
Please, Sign In to add comment