bash – Powershell中的CDPATH功能?
发布时间:2020-12-15 21:45:19 所属栏目:安全 来源:网络整理
导读:有人在Power shell中实现了 bash’s ‘cdpath’的等效行为吗? 解决方法 之前不知道CDPATH.很高兴知道.我为Powershell掀起了以下内容: function cd2 { param($path) if(-not $path){return;} if((test-path $path) -or (-not $env:CDPATH)){ Set-Location $
有人在Power
shell中实现了
bash’s ‘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 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容