DEV Community

John  Ajera
John Ajera

Posted on

Enable Bash-Style History Search and Suggestions in PowerShell

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
Enter fullscreen mode Exit fullscreen mode
  • 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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode
  • Increase history size:
Set-PSReadLineOption -MaximumHistoryCount 10000
Enter fullscreen mode Exit fullscreen mode

Add these lines to your $PROFILE for persistence.


Troubleshooting

Check module and options:

Get-Module PSReadLine
Get-PSReadLineOption
Enter fullscreen mode Exit fullscreen mode

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

Top comments (0)