我最喜欢的Bash技巧之一是创建用于标记和返回目录的别名,如下所述:http://www.huyng.com/archives/quick-bash-tip-directory-bookmarks/492/。Powershell中的目录书签?
在bash,它看起来像这样:
alias m1='alias g1="cd `pwd`"'
是否有可能建立在PowerShell中有类似的功能?
我最喜欢的Bash技巧之一是创建用于标记和返回目录的别名,如下所述:http://www.huyng.com/archives/quick-bash-tip-directory-bookmarks/492/。Powershell中的目录书签?
在bash,它看起来像这样:
alias m1='alias g1="cd `pwd`"'
是否有可能建立在PowerShell中有类似的功能?
您可以添加以下到$profile
:
$marks = @{};
$marksPath = Join-Path (split-path -parent $profile) .bookmarks
if(test-path $marksPath){
import-csv $marksPath | %{$marks[$_.key]=$_.value}
}
function m($number){
$marks["$number"] = (pwd).path
}
function g($number){
cd $marks["$number"]
}
function mdump{
$marks.getenumerator() | export-csv $marksPath -notype
}
function lma{
$marks
}
我不喜欢为每个类似的定义别名的方式m1
,m2
等。相反,你会做m 1
和g 1
等
您还可以添加行
Register-EngineEvent PowerShell.Exiting –Action { mdump } | out-null
,这样它会做mdump
当您退出PowerShell会话。不幸的是,如果你关闭了控制台窗口,但是输入了exit,则不起作用。
PS:也看看CDPATH:CDPATH functionality in Powershell?
我用这一招:
IM我的$的个人资料我写的功能是这样的:
function win { Set-Location c:\windows}
$ProfileDir = $PROFILE.Substring(0 , $PROFILE.LastIndexOf("\")+1)
function pro { Set-Location $profiledir}
等等...
安装:
Install-Module -Name PSBookmark
用途:
#This will save $PWD as scripts
save scripts
#This will save C:\Documents as docs
save docs C:\Documents
#You don't have to type the alias name.
#Instead, you can just tab complete. This function uses dynamic parameters.
goto docs
完美的作品!谢谢! – tltjr