【问题标题】:How to use (Windows Powershell) GitShell commands history after restart?重启后如何使用(Windows Powershell)GitShell 命令历史记录?
【发布时间】:2016-08-27 01:46:17
【问题描述】:

我正在使用从 Github 官方网站下载的适用于 windows (7) 的 Gitshell (Powershell)。重启后如何使用命令历史记录?

  • 命令exit 而不是x 无效(建议here

  • 看不到任何~/.bash_profile~/.bash_history 文件(使其类似于here

【问题讨论】:

    标签: windows powershell git-bash


    【解决方案1】:

    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
    }
    

    但是,这不会使“历史”命令通过光标键可用。如果需要,您需要在 Console2ConEmuClink 之类的文件中运行 PowerShell。

    【讨论】:

    • 你也可以使用#history_id_number标签补全功能。
    • @AnsgarWiechers 我接受了答案,但实际上命令历史 光标键 是我正在寻找的,并且正如您所写的那样,它不可用。它也不适用于 Console2。我放弃了你建议的其他游戏机。
    猜你喜欢
    • 1970-01-01
    • 2013-08-17
    • 2016-02-15
    • 2013-05-04
    • 2019-09-04
    • 1970-01-01
    • 2017-10-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多