-1

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

当我跑

Set-PSReadLineOption -PredictionSource 

历史建议开始出现。

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

我想念什么?

4

1 回答 1

0

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

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

...以及它的选项。

于 2021-06-05T03:27:49.620 回答