Enable Bash-Style History Search and Suggestions in PowerShell



This content originally appeared on DEV Community and was authored by John Ajera

Enable Bash-Style History Search and Suggestions in PowerShell

PowerShell can behave just like Bash with prefix-based history search and inline suggestions. This guide shows how to enable those features in a few simple steps.

Step 1: Check Your PowerShell Version

Run:

$PSVersionTable.PSVersion
  • Version 7+ → PSReadLine is already included.
  • Version 5.1 → install PSReadLine in Step 2.

Step 2: Install PSReadLine (Only for 5.1)

Run PowerShell as Administrator:

Install-Module PSReadLine -Scope CurrentUser -Force -SkipPublisherCheck

This installs or updates PSReadLine for your user.

Step 3: Open Your Profile File

Create or edit your profile file:

# Show profile path
$PROFILE

# Create profile if missing
if (!(Test-Path $PROFILE)) { New-Item -Path $PROFILE -ItemType File -Force }

# Open profile in Notepad
notepad $PROFILE

Step 4: Add History Search and Suggestions

Paste these lines into your profile:

Import-Module PSReadLine
Set-PSReadLineOption -PredictionSource History
Set-PSReadLineOption -PredictionViewStyle InlineView
Set-PSReadLineKeyHandler -Key UpArrow   -Function HistorySearchBackward
Set-PSReadLineKeyHandler -Key DownArrow -Function HistorySearchForward

Save and close Notepad.

Step 5: Restart PowerShell

Close and reopen your PowerShell (or VS Code terminal) to apply changes.

Step 6: Test the Functionality

  1. Run some commands, e.g. echo test
  2. Type ec then press → only commands starting with ec will appear.
  3. Inline suggestions will show in gray — accept with or End.

Optional Tweaks

  • Enable list-style suggestions:
Set-PSReadLineOption -PredictionViewStyle ListView
  • Increase history size:
Set-PSReadLineOption -MaximumHistoryCount 10000

Add these lines to your $PROFILE for persistence.

Troubleshooting

Check module and options:

Get-Module PSReadLine
Get-PSReadLineOption

Ensure PredictionSource is set to History. Restart PowerShell if changes don’t take effect.

Conclusion

With these settings, PowerShell behaves much like Bash, letting you quickly recall previous commands using ↑/↓ and see inline suggestions


This content originally appeared on DEV Community and was authored by John Ajera