DEV Community

Dhravya
Dhravya

Posted on

How to add autocomplete to Powershell in 30 seconds ⚡

One of my friends informed me about this really cool feature that allows you to add autocomplete to Windows powershell in 2 easy steps:

Here’s a demo of what we’ll be doing today (Thanks to nexxel for the blog idea)

https://us-east-1.tixte.net/uploads/img.dhravya.dev/M22.gif

How? By using PSReadLine

Step one

Install PSreadline

Install-Module PSReadLine
Enter fullscreen mode Exit fullscreen mode

Step two

Open your PowerShell PROFILE in your preferred editor (get the file by using $PROFILE )

paste this code snippet:

Import-Module PSReadLine

# Shows navigable menu of all options when hitting Tab
Set-PSReadLineKeyHandler -Key Tab -Function MenuComplete

# Autocompleteion for Arrow keys
Set-PSReadLineOption -HistorySearchCursorMovesToEnd
Set-PSReadLineKeyHandler -Key UpArrow -Function HistorySearchBackward
Set-PSReadLineKeyHandler -Key DownArrow -Function HistorySearchForward

Set-PSReadLineOption -ShowToolTips
Set-PSReadLineOption -PredictionSource History
Enter fullscreen mode Exit fullscreen mode

And that’s it!!

Top comments (6)

Collapse
 
tommdq profile image
Tomas Buzeta

This is great! Thanks for sharing.. but i have a question.. when you are typing you get predictions based on what you wrote sometime.. And you can autocomplete it with right arrow key, right? Do you know how to change that keybind?

Collapse
 
dhravya profile image
Dhravya

honestly, I'm not really sure... and it does work with the tab key

Collapse
 
abhinav1217 profile image
Abhinav Kulshreshtha

Nice share. I hope this works on PS for linux. It's been a long time since I used it on my system.

Collapse
 
dhravya profile image
Dhravya

Thanks, I haven't tried it on linux yet, but probably should work

Collapse
 
gervanna profile image
Gervanna Stephens

Thanks for sharing!

Collapse
 
aurumdev952 profile image
Benjamin

Thanks for sharing