PowerShell 使用 PSReadLine 模组

PowerShell的PSReadLine模组可用来辅助PowerShell来做到类似zsh的效果:根据命令列历史提示自动完成,以及可用方向键在选单式介面选择候选命令/路径的功能。
在PowerShell v7.2之后已经内建PSReadLine,不必额外指令安装,你只需要在PowerShell的Profile档案内加入下面这段:

Import-Module PSReadLine# Shows navigable menu of all options when hitting TabSet-PSReadLineKeyHandler -Key Tab -Function MenuComplete# Autocompleteion for Arrow keysSet-PSReadLineOption -HistorySearchCursorMovesToEndSet-PSReadLineKeyHandler -Key UpArrow -Function HistorySearchBackwardSet-PSReadLineKeyHandler -Key DownArrow -Function HistorySearchForwardSet-PSReadLineOption -ShowToolTips

之后开启PowerShell视窗就可以使用,其他例如预测字串颜色之类的微调可参考微软PowerShell开发团队的部落格文章:
https://devblogs.microsoft.com/powershell/psreadline-2-2-6-enables-predictive-intellisense-by-default/


关于作者: 网站小编

码农网专注IT技术教程资源分享平台,学习资源下载网站,58码农网包含计算机技术、网站程序源码下载、编程技术论坛、互联网资源下载等产品服务,提供原创、优质、完整内容的专业码农交流分享平台。

热门文章