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

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

Open
CarltonSemple opened this issue Oct 14, 2017 · 13 comments
Labels
Area-HistoryImprovements Label for tracking different improvements to history Issue-Enhancement It's a feature request.

Comments

@CarltonSemple
Copy link

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

@markekraus
Copy link

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?

@lzybkr
Copy link
Member

lzybkr commented Oct 14, 2017

Yes, PSReadLine does this by default.

@CarltonSemple
Copy link
Author

CarltonSemple commented Oct 14, 2017

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

@markekraus
Copy link

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

@CarltonSemple
Copy link
Author

CarltonSemple commented Oct 14, 2017

@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

@CarltonSemple
Copy link
Author

I'm using Windows 10

@markekraus
Copy link

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

@rkeithhill
Copy link
Contributor

rkeithhill commented Oct 14, 2017

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

@CarltonSemple
Copy link
Author

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

@CarltonSemple CarltonSemple changed the title Feature Request: Cross session command history Feature Request: Get-History command showing history from previous sessions Oct 14, 2017
@rkeithhill
Copy link
Contributor

rkeithhill commented Oct 14, 2017

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.

@markekraus
Copy link

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.

@iSazonov
Copy link

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

@SteveL-MSFT SteveL-MSFT transferred this issue from PowerShell/PowerShell Sep 28, 2019
@lzybkr lzybkr added the Issue-Enhancement It's a feature request. label Oct 19, 2019
@espoelstra
Copy link
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-HistoryImprovements Label for tracking different improvements to history Issue-Enhancement It's a feature request.
Projects
None yet
Development

No branches or pull requests

7 participants