windows Powershell如何增加history命令并提示。

403 阅读1分钟

管理员运行终端,内输入

Get-Module -ListAvailable PSReadLine
Install-Module PSReadLine

注意,这里可能会提示你系统已安装了2.0.0版本,要不要升级,根据提示升级,不然下方的History参数识别不了。

编辑器打开$PROFILE文件,如果系统安装了vscode,命令为

code $PROFILE

打开文件后添加如下内容:

#Imports PSReadLine
Import-Module PSReadLine

#Tab - Gives a menu of suggestions
Set-PSReadLineKeyHandler -Key Tab -Function MenuComplete

#UpArrow will show the most recent command
Set-PSReadLineKeyHandler -Key UpArrow -Function HistorySearchBackward

#DownArrow will show the least recent command
Set-PSReadLineKeyHandler -Key DownArrow -Function HistorySearchForward

#During auto completion, pressing arrow key up or down will move the cursor to the end of the completion
Set-PSReadLineOption -HistorySearchCursorMovesToEnd

#Shows tooltip during completion
Set-PSReadLineOption -ShowToolTips

#Gives completions/suggestions from historical commands
Set-PSReadLineOption -PredictionSource History

保存,重新打开终端,Done:

image.png