This is a small but powerful improvement for PowerShell. I regularly use PowerShell to run commands for my programming work like starting builds, deploying cloud functions, running scripts etc..
The press arrow up feature to get the previous command is very helpful, but cumbersome to use when repeating the same command often.
When developing, I often have to run the same commands a lot of times in a row.
Example:
1.) start server command
2.) change code -> run script command
3.) change code -> run script command
.....
50.) change code -> run script command
ends coding session
Now here is the issue. The next time I start the terminal I would like to select the start server command again by pressing arrow up button. The problem is though, that I have to press is like 50 times before it shows that command. I'm assuming that there is some kind of list that is iterated through 1 row each time the arrow up button is pressed.
It would be extremely helpful, if the "press arrow up"-function would not repeat the same command, but always show the next different command. (increase i until next command is different then currently show command). (same goes for arrow down)
In my example that would mean: When I start the terminal and press arrow up once it shows the "run script command" and when pressing it the second time it shows the " start server command"
Maybe you can make that change? I would SO MUCH appreciate it!
You can do this with PSReadline (which is the line editor and history management module that ships with powershell, and which you鈥檙e already using) today with...
Set-PSReadLineOption -HistoryNoDuplicates
If you put that into your profile, you won鈥檛 see duplicates in your history file or your up-arrow history recall.
(As an aside, you can actually search your history interactively with Ctrl+R! If you press ^R and then part of the command that starts the server, it鈥檒l automatically jump to that command so you can run it again.)
You Sir, deserve more than the one upvote I can give.
imho this should be the default setting
An even more straightforward way to search is to type in the first part of the command e.g. start
and then press the UpArrow key. IIRC you need this bit of configuration to make that work:
Set-PSReadlineKeyHandler -Chord UpArrow -Function HistorySearchBackward
Set-PSReadlineKeyHandler -Chord DownArrow -Function HistorySearchForward
Finally, give the new PSRL 2.1.0 Beta a try. It provides completion prediction functionality (I typed in only dot
below - the rest is the prediction) e.g.:
See this PSReadLine issue for more details: https://github.com/PowerShell/PSReadLine/issues/687
I wish I could preset these somehow. Having to enter them at the beginning each time is really slowing me down :/
So that's what I was alluding to when I mentioned your profile. You can have a script that runs automatically every time you open PowerShell to set your customizations up exactly as you want them.
Ok I will try that. Thanks!
This issue has been marked as answered and has not had any activity for 1 day. It has been closed for housekeeping purposes.
Most helpful comment
(As an aside, you can actually search your history interactively with Ctrl+R! If you press ^R and then part of the command that starts the server, it鈥檒l automatically jump to that command so you can run it again.)