5
Est-ce que quelqu'un a implémenté le comportement équivalent de bash's 'cdpath' dans Powershell?Fonctionnalité CDPATH dans Powershell?
Est-ce que quelqu'un a implémenté le comportement équivalent de bash's 'cdpath' dans Powershell?Fonctionnalité CDPATH dans Powershell?
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
Excellent! Je vous remercie. –