Powershell Autosuggestions like Fish,zsh-autosuggestions

Photo by Windows on Unsplash

Powershell Autosuggestions like Fish,zsh-autosuggestions

One of the things I like from zsh is the zsh-autosuggestion plugin. For Powershell Predictive IntelliSense is here to help.

Screenshot (2).png

For Powershell, it's called predictive IntelliSense in PSReadLine.

Predictive IntelliSense is implemented in the PowerShell engine and presented through the PSReadLine module and provide History based prediction in the InlineView.

Predictive IntelliSense is an addition to the concept of tab completion that assists the user in successfully completing commands based on matching predictions from the user’s history.

The prediction suggestion appears as colored text following the user’s cursor.

Installing Predictive IntelliSense

The current release is PSReadLine 2.1.0:

Install-Module PSReadLine -RequiredVersion 2.1.0

If you have vscode installed, simply type code $PROFILE in the terminal. If not simply create Microsoft.PowerShell_profile.ps1 file in this path...

C:\Users\<UserName>\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1

Now in the $PROFILE of powershell, add the following :


Import-Module PSReadLine

Set-PSReadLineOption -PredictionSource History

Set-PSReadLineOption -HistorySearchCursorMovesToEnd
Set-PSReadLineKeyHandler -Key UpArrow -Function HistorySearchBackward
Set-PSReadLineKeyHandler -Key DownArrow -Function HistorySearchForward

Set-PSReadLineOption -Colors @{ InlinePrediction = '#875f5f'}


Set-PSReadLineKeyHandler -Chord "Ctrl+RightArrow" -Function ForwardWord

Documentation about the code can be found here.

Preview:

Windows PowerShell 2022-11-11 01-30-37.gif

For more you can refer here .