Powershell autocomplete with PSReadLine

As of powershell 6 you have a module called PSReadLine installed by default. This module changes the editing experience of powershell and is customizable. One thing that I really like is to have auto completion for historical commands. In this post I will show you how I setup PSReadLine in my profile.

Start by installing PSReadLine.

Get-Module -ListAvailable PSReadLine
Install-Module PSReadLine

Then open up profile code $PROFILE


#Imports PSReadLine
Import-Module PSReadLine

#Tab - Gives a menu of suggestions
Set-PSReadLineKeyHandler -Key Tab -Function MenuComplete

#UpArrow will show the most recent command
Set-PSReadLineKeyHandler -Key UpArrow -Function HistorySearchBackward

#DownArrow will show the least recent command
Set-PSReadLineKeyHandler -Key DownArrow -Function HistorySearchForward

#During auto completion, pressing arrow key up or down will move the cursor to the end of the completion
Set-PSReadLineOption -HistorySearchCursorMovesToEnd

#Shows tooltip during completion
Set-PSReadLineOption -ShowToolTips

#Gives completions/suggestions from historical commands
Set-PSReadLineOption -PredictionSource History

powershell-psreadline-autocompletion

powershell-psreadline-autocompletion

More about PSReadLine can be found here: https://github.com/PowerShell/PSReadLine

Happy coding!

Please share
𝕏finLINEtIw