-
-
Save potoo0/21a0ef756d29c594af2c2c8c36836b60 to your computer and use it in GitHub Desktop.
Powershell fish prompt
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 replaceHome($pathArray) { | |
# Check whether the first three paths are equal to HOME | |
# If it is, it substitutes it for ~ | |
# Change this accordingly, if your home path is more than three | |
# paths long. | |
$splitChar = [System.IO.Path]::DirectorySeparatorChar | |
if ( ($pathArray.Length -gt 2) -and | |
(($pathArray[0..2] -join $splitChar) -eq $HOME)) { | |
@("~") + $pathArray[3..$pathArray.Length] | |
} | |
else { | |
$pathArray | |
} | |
} | |
function fish_prompt { | |
$splitChar = [System.IO.Path]::DirectorySeparatorChar | |
$currLocation = (Get-Location) | |
if ($currLocation.ToString() -eq $HOME) { | |
# Special case the home directory | |
"~>" | |
} | |
else { | |
$current = Split-Path -Leaf -Path $currLocation | |
$parent = Split-Path -Parent -Path $currLocation | |
$folders = $parent.Split($splitChar, [System.StringSplitOptions]::RemoveEmptyEntries) | |
if ($folders.Length -lt 2) { | |
# If the path is 0 or 1, then ignore. | |
$currLocation.ToString() + ">" | |
} | |
else { | |
$folders = replaceHome($folders) # optional, to get the ~/Docs effect | |
# Replace everything except the first name | |
# Note: On line 35, (+) for array concat avoids issue of empty arr | |
$firstNameFolders = ForEach ($f in $folders[1..$folders.Length]) { $f[0] } | |
$folders = @($folders[0]) + $firstNameFolders + @($current) | |
($folders -join $splitChar) + ">" | |
} | |
} | |
} | |
function prompt { | |
fish_prompt | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment