Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PowerShell 中获取全部会话的 History #76

Open
woodongwong opened this issue Apr 11, 2023 · 0 comments
Open

PowerShell 中获取全部会话的 History #76

woodongwong opened this issue Apr 11, 2023 · 0 comments

Comments

@woodongwong
Copy link
Owner

我用惯了 bash shell 中的 history 命令,发现 PowerShell 中的 history 只能列出当前会话的,通过 Get-Alias 列出所有的 alias ,发现 history 是 Get-History 的别名。

Get-History 只能列出当前会话的历史记录,想要列出所有会话的历史记录,需要查看 ConsoleHost_history.txt 文件。

ConsoleHost_history.txt 中记录了所有会话的历史记录,可以通过(Get-PSReadlineOption).HistorySavePath获取绝对路径,然后再通过Get-Content获取文件内容。

完整的命令是:Get-Content -Path (Get-PSReadlineOption).HistorySavePath,最后在profile中设置一个别名history-all,可以使用notepad $PROFILE打开 profile,将下面的代码放进去,这样就可以在 PowerShell 中使用history-all列出全部记录啦😄。

function Get-History-All
{
    Get-Content -Path (Get-PSReadlineOption).HistorySavePath
}

New-Alias history-all Get-History-All
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant