环境
Windows Terminal + Power Shell (Power Shell Core)
实现
默认情况下,Power Shell 的 history 这个命令是获取当前session下的历史命令(打开这个窗口执行过的操作),与linux下的history行为不一样。
Power shell可以通过下面这个API获取到历史执行命令。
PS C:\Users\Administrator> Get-Content (Get-PSReadlineOption).HistorySavePath
可以配合管道进行处理,如进行搜索 ssh 相关的历史命令:
PS C:\Users\Administrator> Get-Content (Get-PSReadlineOption).HistorySavePath | findstr ssh
参考
官方文档:
- Get-PSReadlineOption: https://docs.microsoft.com/en-us/powershell/module/psreadline/get-psreadlineoption?view=powershell-7.2
- Alias: https://docs.microsoft.com/zh-cn/powershell/module/microsoft.powershell.core/about/about_aliases?view=powershell-7.2
- Get-Content: https://docs.microsoft.com/zh-cn/powershell/module/microsoft.powershell.management/get-content?view=powershell-7.2