Add keyboard navigable and filterable history to Windows PowerShell and PowerShell Core. Once an item is selected the menu is cleared from the console but your buffer is not erased meaning you can still scroll up and view previously executed commands.
This is an adaptation of an example by Jeff Hicks on Petri.com where he used the PSReadline History with Out-GridView
to make selectable history. I liked the idea but wanted something that wouldn't take me out of the console. This is an early pass taking what I had in my profile and adapting it in to a module to make it easier to share but a number of improvements are planned.
Install-Module AdvancedHistory -Scope CurrentUser
git clone https://github.com/omniomi/AdvancedHistory.git
cd .\AdvancedHistory\tools
.\Build.ps1 Install
The easiest way to ensure that AdvancedHistory is always available is to add it to your $PROFILE. Simply add these two lines anywhere in your PowerShell profile:
Import-Module AdvancedHistory
Enable-AdvancedHistory
By default AdvancedHistory uses F7 for accessing the history menu. To change the shortcut specify the key or keys as a string following Enable-AdvancedHistory
. For example, to use Ctrl+F7 you would use Enable-AdvancedHistory 'Ctrl+F7'
To only show unique commands from your history once (most recent execution) use the -Unique
switch on Enable-AdvancedHistory
.
By default the AdvancedHistory will limit the menu to 256 items whether unique or not. To override the limit set $Global:HistoryCountOverride = <number>
either in your PowerShell Profile or at the CLI as needed. For example, $Global:HistoryCountOverride = 512
NOTE: The history override must come before
Enable-AdvancedHistory
.# $Profile Import-Module AdvancedHistory $Global:HistoryCountOverride = 512 Enable-AdvancedHistory
To access the AdvancedHistory menu press either F7 or the keyboard shortcut you specified when setting it up.
- Up/Down Arrows: Navigate the list
- Right/Left Arrows: Change the page
- Enter/Return: Select the highlighted line item
- Esc: Cancel
To filter the search type any part of the command at the prompt before pressing the activation key.
C:\> mkdir MyProject
C:\> cd .\MyProject\
C:\MyProject\> MyProj<F7>
Select a Command (it will be inserted at the prompt but not executed)
cd .\MyProject\
mkdir MyProject
Page: 1 / 1
- Requires PSReadline (included in PowerShell >=5.0)