【发布时间】:2016-08-27 01:46:17
【问题描述】:
我正在使用从 Github 官方网站下载的适用于 windows (7) 的 Gitshell (Powershell)。重启后如何使用命令历史记录?
【问题讨论】:
标签: windows powershell git-bash
我正在使用从 Github 官方网站下载的适用于 windows (7) 的 Gitshell (Powershell)。重启后如何使用命令历史记录?
【问题讨论】:
标签: windows powershell git-bash
PowerShell 没有持久的历史记录。您可以(在某种程度上)save/restore 自己使用以下命令历史记录:
Get-History | Export-Clixml 'C:\path\to\history.xml'
Import-Clixml 'C:\path\to\history.xml' | Add-History
使用Get-History 列出历史记录,使用Invoke-History 从历史记录调用命令。保存和恢复可以通过将这样的东西放入你的 PowerShell profile 来自动化:
Register-EngineEvent -SourceIdentifier PowerShell.Exiting -Action {
Get-History | Export-Clixml "$env:USERPROFILE\ps_history.xml"
} | Out-Null
if (Test-Path -LiteralPath "$env:USERPROFILE\ps_history.xml") {
Import-Clixml "$env:USERPROFILE\ps_history.xml" | Add-History
}
但是,这不会使“历史”命令通过光标键可用。如果需要,您需要在 Console2、ConEmu 或 Clink 之类的文件中运行 PowerShell。
【讨论】:
#history_id_number标签补全功能。