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.
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.
Notice that when browsing the cmdlet parameters it also displays the parameter’s type.
e.g. It shows that
-Path is a
-Force is a
This works for cmdlets, parameters, variables, methods, and more. Basically anything that you can tab complete, you can also see in the menu. For example:
Get-Prothen Ctrl + Space to see all cmdlets that start with
- If you have the variables
$variable2, then type
$varand Ctrl + Space to see both variables in the menu.
[string]::and Ctrl + Space to see all the methods available on the
Anytime you want autocomplete, just hit Ctrl + Space and you’ll see all the options available.
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 *