brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: HistorySearchBackward on the Up arrow in the PowerShell terminal

Terminal
~/tips/tip-terminal-psreadline-history-search

Set-PSReadLineKeyHandler -Chord UpArrow -Function HistorySearchBackward

Makes Up and Down in PowerShell return only commands that start with your text.

In PowerShell, Up scrolls through all of your history. With one PSReadLine setting it only shows earlier commands that start with what you already typed.

PSReadLine, the module that handles line editing in PowerShell, has a function called HistorySearchBackward. Bind it to the arrow keys:

Set-PSReadLineKeyHandler -Chord UpArrow -Function HistorySearchBackward
Set-PSReadLineKeyHandler -Chord DownArrow -Function HistorySearchForward

Now type Get-Ch and press Up: you get your earlier Get-ChildItem lines and nothing else. On an empty line Up still walks the full history.

These bindings only last for the current session. To keep them, put both lines in your profile, the file whose path is in $PROFILE. Open it with notepad $PROFILE and paste them in.

To see what is bound already, and which other functions exist, run:

Get-PSReadLineKeyHandler

One clash to watch for: with predictions turned on, Up and Down can also be busy with the prediction list view. I find this binding works best with the inline prediction style, or with predictions off. It is the same idea as history-search-backward in bash’s ~/.inputrc, so it is nice when your fingers switch between a Mac and Windows all day.

Further reading: Set-PSReadLineKeyHandler (Microsoft Learn), about_Profiles (Microsoft Learn)

More Terminal tips ioreg -rn AppleSmartBattery | grep CycleCount Terminal can save your windows and tabs as a window group Export a Terminal profile to a .terminal file and import it on another Mac mc hidutil property --set '{"UserKeyMapping":[{"HIDKeyboardModifierMappingSrc":0x700000039,"HIDKeyboardModifierMappingDst":0x700000029}]}' All Terminal tips (116) All topics

Link