Skip to content

Instantly share code, notes, and snippets.

@gyuwon
Last active August 29, 2015 14:27
Show Gist options
  • Save gyuwon/ae375561665b85307d6c to your computer and use it in GitHub Desktop.
Save gyuwon/ae375561665b85307d6c to your computer and use it in GitHub Desktop.
Get-DirAlias
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