DEV Community

Thomas Alcala Schneider
Thomas Alcala Schneider

Posted on

Fish-like Autosuggestion in Powershell

For a year, working on Windows laptops has been nonoptional for me. I've been desperately trying to make my environment as close as it is on Mac OS, with the added challenge to do it without the Windows Subsystem for Linux (WSL). So this relies heavily on Powershell.

One thing I like from the fish shell (and was reproduced in zsh by the zsh-autosuggestion plugin) is the autosuggestion feature.

It's that thing where when you start typing something and there is something that starts with the same letters in your history, it'll write it after the cursor in grayed colors. And it's awesome.

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

Prerequisites

  • Powershell 5.1 or higher

Installation

  1. First, install ´PSReadLine´ version 2.1.0

    Install-Module PSReadLine -RequiredVersion 2.1.0
    
  2. Then, initialize it with the command below

    Import-Module PSReadLine
    Set-PSReadLineOption -PredictionSource History
    

And there it is!

(Optional) Initialize it in your profile

  1. Check if you already have a profile

    Test-path $profile
    
  2. If false, create one

    New-item –type file –force $profile
    
  3. If yes, edit it

    notepad $profile
    
  4. Run this command and close your terminal

    Set-ExecutionPolicy RemoteSigned
    
  5. Update your profile file like in step 3, and add those lines to it

    Import-Module PSReadLine
    Set-PSReadLineOption -PredictionSource History
    

And that's it!

Autosuggest in Powershell

Top comments (8)

Collapse
 
fcoclavero profile image
Francisco Clavero • Edited

Thanks a lot!

If you get the following error:

Set-PSReadLineOption : A parameter cannot be found that matches parameter name 'PredictionSource'
Enter fullscreen mode Exit fullscreen mode

installing a prerelease may solve the issue:

Install-Module -Name PSReadLine -AllowPrerelease -Scope CurrentUser -Force -SkipPublisherCheck
Enter fullscreen mode Exit fullscreen mode
Collapse
 
parshuram-patil profile image
Parshuram Patil • Edited

I am able to get the autosuggestions but still unable to get ZSH like view like green >, colors, etc. Am I missing something?

Image description

Collapse
 
castellodev profile image
CastelloDev

The gif seems to be using starship terminal:
starship.rs/

Collapse
 
cisnuxseed profile image
Cisnux

Thanks bro, this useful for me

Collapse
 
matrixcloud profile image
atom

thanks, very useful.

Collapse
 
wangaevans profile image
Wanga Evans

Thanks alot! I Love it

Collapse
 
ffrmns profile image
ffrmns

Thanks, this will help learning powershell in ease

Collapse
 
dphov profile image
Dmitry Petukhov

Thank you, Thomas
Now it looks more like fish :)