Created
May 16, 2018 17:12
-
-
Save jaredcnance/87af2ec3f0c7db8aca9323b7a5ca5488 to your computer and use it in GitHub Desktop.
Powershell 'cd' alias
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
# usage: . ./cd-alias.ps1 | |
# cd .. | |
function CheckLastExitCode { | |
param ([int[]]$SuccessCodes = @(0), [scriptblock]$CleanupScript=$null) | |
if ($SuccessCodes -notcontains $LastExitCode) { | |
$msg = "EXE RETURNED EXIT CODE $LastExitCode" | |
throw $msg | |
} | |
} | |
function Internal-Change-Directory { | |
if(Test-Path "$args") { | |
Set-Location "$args"; | |
CheckLastExitCode | |
ls; | |
} | |
else { | |
Write-Output "$args is not a directory" | |
} | |
} | |
Remove-Item alias:cd | |
New-Alias cd Internal-Change-Directory -Option AllScope |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment