Skip to content

Feature Request: Get-History command showing history from previous sessions #1074

Open

Description

Apparently there are community-provided solutions for this, but it would be nice to have a built-in solution for saving command history across sessions, similar to Bash.

Jeffrey Snover (@jpsnover) https://twitter.com/jsnover/status/919145208255799296

Activity

  1. markekraus commented on Oct 14, 2017

    @markekraus

    Unless I'm doing something special I'm aware of, doesn't PSReadLine do this by default in Core?

    Can you provide what specific bash-like functionality you are looking for?

  2. lzybkr commented on Oct 14, 2017

    @lzybkr
    Contributor

    Yes, PSReadLine does this by default.

  3. CarltonSemple commented on Oct 14, 2017

    @CarltonSemple
    Author

    So, i downloaded and tried PowerShell 6.0.0-beta.7. The desired functionality would be that the history command would show the history from the previous session, without any additional work

  4. markekraus commented on Oct 14, 2017

    @markekraus

    Carlton Semple (@CarltonSemple) Correct. Assuming you don't have something in your profile that is disabling PSReadLine, and assuming you are not making any modifications to the default install 6.0.0-beta.7 and 6.0.0-beta.8 should maintain CLI history between sessions.

  5. CarltonSemple commented on Oct 14, 2017

    @CarltonSemple
    Author

    Mark Kraus (@markekraus) I deleted my profile files just now, and tried 6.0.0-beta.8 .... history and Get-History still don't show CLI history from the previous session for me

  6. CarltonSemple commented on Oct 14, 2017

    @CarltonSemple
    Author

    I'm using Windows 10

  7. markekraus commented on Oct 14, 2017

    @markekraus

    Carlton Semple (@CarltonSemple) ah Get-History only provides commands for the current session. However you can use the up arrow to access the commands from the previous session. and there are more options such as searching and such. I'm not a PSReadLine expert.

  8. rkeithhill commented on Oct 14, 2017

    @rkeithhill
    Contributor

    You can search backwards with Ctrl+r. If you go too far, use Ctrl+s to move forward through the matching history list.

  9. CarltonSemple commented on Oct 14, 2017

    @CarltonSemple
    Author

    Mark Kraus (@markekraus) I guess maybe I should change the title to specifically reference the Get-History command, then.

  10. changed the title [-]Feature Request: Cross session command history[/-] [+]Feature Request: `Get-History` command showing history from previous sessions[/+] on Oct 14, 2017
  11. rkeithhill commented on Oct 14, 2017

    @rkeithhill
    Contributor

    Possibly but the point, I think, is that PSReadline (inspired by GNU Readline), was created to provide such features. Get-History is legacy command that is still useful IMO as more of "audit" trail for the current session. Back in the old days, I use to save the Get-History history to files by adding this to my profile:

    $historyPath = Join-Path (Split-Path $profile) "history-$(Get-Date -f o)-$pid.clixml"
    Register-EngineEvent -SourceIdentifier powershell.exiting -SupportEvent -Action {
        Get-History | Export-Clixml $historyPath
    }.GetNewClosure()
    

    I'm not sure if this will work on PowerShell Core. I also had find functions I had defined that could search these history files. I don't use these so much anymore because PSReadline scratched that itch pretty nicely.

  12. markekraus commented on Oct 14, 2017

    @markekraus

    I think some parity with bash's history from PSReadLine would be nice to have. I definitely have done history | more a million times trying to trace back the command history to see where things went wrong or when I'm trying to remember a command I don't recall enough of the syntax to make keyword searching the history useful.

  13. iSazonov commented on Sep 28, 2019

    @iSazonov

    Steve Lee (@SteveL-MSFT) Dongbo Wang (@daxian-dbw) Could you please make a conclusion - should we enhance Get-History cmdlet in the repo (change label to Area-Cmdlets-Core) or PSReadline (in the case please move the issue in PSReadline repo)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions