I did not know about CDPATH before. Good to know. I hacked below for Powershell:
function cd2 {
param($path)
if(-not $path){return;}
if((test-path $path) -or (-not $env:CDPATH)){
Set-Location $path
return
}
$cdpath = $env:CDPATH.split(";") | % { $ExecutionContext.InvokeCommand.ExpandString($_) }
$npath = ""
foreach($p in $cdpath){
$tpath = join-path $p $path
if(test-path $tpath){$npath = $tpath; break;}
}
if($npath){
Set-Location $npath
return
}
set-location $path
}
It will not be perfect, but it works on hold. You can extend it, I think. Add it to your profile. If necessary, also add an alias:
set-alias -Name cd -value cd2 -Option AllScope
source
share