Last active
August 29, 2015 14:27
-
-
Save gyuwon/ae375561665b85307d6c to your computer and use it in GitHub Desktop.
Get-DirAlias
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
function Get-DirAlias ([string]$loc) { | |
# check if we are in our home script dir | |
# in that case return grave sign | |
if ($loc.Equals([Environment]::GetFolderPath("UserProfile"))) { | |
return "~" | |
} | |
# if it ends with \ that means we are in root of drive | |
# in that case return drive | |
$lastindex = [int] $loc.lastindexof("\") | |
if ($loc.EndsWith("\")) { | |
return $loc.Remove($lastindex, 1) | |
} | |
# Otherwise return only the dir name | |
$lastindex += 1 | |
$loc = $loc.Substring($lastindex) | |
return $loc | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment