PSReadLine 历史不加载

PSReadLine history doesn't load

我今天尝试使用 psreadline。我不明白的是历史命令。

当我运行

Set-PSReadLineOption -PredictionSource 

历史建议开始显示。

我关闭终端 ps,再次打开它,在我再次 运行 命令之前没有历史建议。

我错过了什么?

如果这是您使用的唯一命令...

Set-PSReadLineOption -PredictionSource

..那还不完整

根据此处的 Powershell 文档:MS Docs | PSReadLine

-PredictionSource
Specifies the source for PSReadLine to get predictive suggestions.

Valid values are:

None: disable the predictive suggestion feature
History: get predictive suggestions from history only

所以你必须告诉它你想要什么:

Set-PSReadLineOption -PredictionSource History

Set-PSReadLineOption -PredictionSource None

不说的话默认是后者。 只需将前者放入所有控制台配置文件即可。

Get-PSReadLineOption
<#
EditMode                               : Windows
AddToHistoryHandler                    : System.Func`2[System.String,System.Object]
HistoryNoDuplicates                    : True
HistorySavePath                        : C:\Users\WDAGUtilityAccount\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadLine\ConsoleHost_history.txt
...
PredictionSource                       : None
...
#>

请务必阅读...

Set-PSReadLineOption -HistorySaveStyle

...及其选项。