DEV Community

loading...

Fish-like Autosuggestion in Powershell

animo profile image Thomas Alcala Schneider ・2 min read

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

Discussion (0)

pic
Editor guide