5
有沒有人在Powershell中實現bash's 'cdpath'的等效行爲?Powershell中的CDPATH功能?
有沒有人在Powershell中實現bash's 'cdpath'的等效行爲?Powershell中的CDPATH功能?
以前不知道CDPATH。很高興知道。我爲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
}
它不會是完美的,但以預期的方式工作。我猜你可以擴展它。將它添加到你的個人資料。如果需要,還可以添加別名,如下所示:
set-alias -Name cd -value cd2 -Option AllScope
非常好!謝謝。 –