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/