PowerShell intellisense on the command line

1 minute read

If you use PowerShell then this tip is for you; if you don’t already know it, it’s game changer!

You may already know that you can use Tab to autocomplete cmdlet names and parameters in the console. If there’s more than one possible match, you can continue hitting Tab to cycle through them, and Shift + Tab to cycle in reverse order.

Screencast showing tab completion

Things get even better by using PSReadLine. Not only can you autocomplete cmdlets and parameters, but you can see all of the options available in a nice menu that you can navigate using the arrow keys. You activate this menu by using Ctrl + Space.

Screencast showing PSReadLine menu completion

Notice that when browsing the cmdlet parameters it also displays the parameter’s type. e.g. It shows that -Path is a [string[]], and -Force is a [switch]. Very helpful!

If you’re on a Mac, then apparently the Ctrl + Space trigger won’t work; I don’t have a Mac, so I can’t confirm. However, do not fret. You can achieve the same functionality by adding this PowerShell code to your PowerShell profile:

Set-PSReadLineKeyHandler -Chord Shift+Spacebar -Function MenuComplete

Now you should be able to activate the menu by using Shift + Spacebar. Of course you can choose a different keyboard combination if you like, including overriding the default Tab behaviour with this, and this trick also works on Windows if you don’t like the default Ctrl + Space trigger.

A shout-out to Steve Lee of the PowerShell team for showing me the Menu Complete functionality in this tweet.

I hope you’ve found this information helpful.

Happy command lining :)

Leave a Comment

Your email address will not be published. Required fields are marked *