Skip to content

Instantly share code, notes, and snippets.

@jaredcnance
Created May 16, 2018 17:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaredcnance/87af2ec3f0c7db8aca9323b7a5ca5488 to your computer and use it in GitHub Desktop.
Save jaredcnance/87af2ec3f0c7db8aca9323b7a5ca5488 to your computer and use it in GitHub Desktop.
Powershell 'cd' alias
# 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