In Powershell, is there a way to save a typed command into history without executing it for later execution

command linehistorypowershell

In PowerShell, is there a way, after typing a long or complicated command, to commit that command into the history buffer, but not execute it?

For example, you start typing a git commit, within posh-git:directory:

git commit -m "Added the library 'ASDF' and did some initial integration into the project" [pause]

And right when you get that typed, I'm thinking… Uh, I need to do something first, like add an additional file to commit do something else first, or create a directory or something (contrived situation, I realize PowerShell will auto-create it and I realize git can "amend the commit".) So I'd like to save that commit message into a history buffer, but without running it, to be recalled later after I say, stage additional files or do something just before.

According to this article, Windows PowerShell Shortcut Keys, there doesn't appear to be a keystroke to do this.

Esc key (and Ctrl+C) will cancel the command, and clear it out… What I need is to save to history, to be run later, thus preserving my typing. Is there a keystroke for this?

Best Answer

Well you can always put a comment tag before the command like this:

#Get-ChildItem

And when you are ready to execute, arrow up to the command hit Home then Del, then Enter to execute.

Related Question