我最喜欢的 Bash 技巧之一涉及创建别名来标记和返回目录,如下所述:http : //www.huyng.com/archives/quick-bash-tip-directory-bookmarks/492/。
在 Bash 中,它看起来像这样:
alias m1='alias g1="cd `pwd`"'
Run Code Online (Sandbox Code Playgroud)
是否可以在powershell中创建类似的功能?
这个项目效果很好:http : //www.powershellmagazine.com/2016/05/06/powershell-location-bookmark-for-easy-and-faster-navigation/
安装:
Install-Module -Name PSBookmark
Run Code Online (Sandbox Code Playgroud)
用:
#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
Run Code Online (Sandbox Code Playgroud)
您可以将以下内容添加到$profile:
$marks = @{};\n\n$marksPath = Join-Path (split-path -parent $profile) .bookmarks\n\nif(test-path $marksPath){\nimport-csv $marksPath | %{$marks[$_.key]=$_.value}\n}\n\nfunction m($number){\n$marks["$number"] = (pwd).path\n}\n\nfunction g($number){\ncd $marks["$number"]\n}\n\nfunction mdump{\n$marks.getenumerator() | export-csv $marksPath -notype\n}\n\nfunction lma{\n$marks\n}\nRun Code Online (Sandbox Code Playgroud)\n\n我不喜欢为每个 like 定义别名的方式m1,m2等等。相反,你会做m 1等等g 1。
您还可以添加以下行
\n\nRegister-EngineEvent PowerShell.Exiting \xe2\x80\x93Action { mdump } | out-null\nRun Code Online (Sandbox Code Playgroud)\n\n这样mdump当您退出 Powershell 会话时它就会执行。不幸的是,如果您关闭控制台窗口,但当您键入 exit 时,则不起作用。
PS:另外看看CDPATH:Powershell中的CDPATH功能?
\n