2011-08-29 4 views

Répondre

6

Je ne connaissais pas le protocole CDPATH auparavant. Bon à savoir. Je fouetté le ci-dessous pour 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){ 
     #write-host -fore yellow "Using CDPATH" 
     Set-Location $npath 
     return 
    } 

    set-location $path 

} 

Il ne sera pas parfait, mais fonctionne de la manière attendue. Vous pouvez l'étendre je suppose. Ajoutez-le à votre profil. Si nécessaire, ajoutez également un alias comme ceci:

set-alias -Name cd -value cd2 -Option AllScope 
+0

Excellent! Je vous remercie. –