Psreadline: Feature Request: `Get-History` command showing history from previous sessions

Created on 14 Oct 2017  路  13Comments  路  Source: PowerShell/PSReadLine

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.

@jpsnover https://twitter.com/jsnover/status/919145208255799296

Issue-Enhancement

All 13 comments

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?

Yes, PSReadLine does this by default.

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

@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.

@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

I'm using Windows 10

@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.

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

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

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.

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.

@SteveL-MSFT @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)?

Was this page helpful?
0 / 5 - 0 ratings