r/PowerShell • u/omers • Aug 30 '17
[TIL] You can change the tab complete behaviour in newer versions of PowerShell
One of my biggest gripes with PowerShell's tab complete has always been that I type Get-AD<tab> looking for Get-ADUser but get Get-ADAccountAuthorizationGroup instead and have to backspace all those characters or hit tab 50 times to get to ADUser.
I much prefer how bash works and today it was pointed out to me that you can come close in PowerShell:
Set-PSReadlineKeyHandler -Key Tab -Function CompleteWhich is bash like or another option:
Set-PSReadlineKeyHandler -Key Tab -Function MenuCompleteWhich gives you an arrow navigable list of possible completion choices and is also kind of bash like.
You can set it on demand or add it to your $Profile. There's a bunch of other cool stuff in PSReadLine https://docs.microsoft.com/en-us/powershell/module/psreadline/?view=powershell-5.1 but I think tab completion control takes the cake for me. It's not perfect but it's better than the default. (Ctrl+Space is 'MenuComplete' by default if you do not want to change tab itself. Get-PSReadlineKeyHandler)
17
u/Thotaz Aug 30 '17 edited Aug 30 '17
You just solved my biggest gripe with working in the powershell console. I've almost always used ISE, even when writing short oneliners because it's just easier to use the less commonly used cmdlets when you can see the full list of parameters they take instead of either tabbing through them one by one or running get-command -syntax in a separate window.
-Edit: Set-PSReadlineOption -ShowToolTips makes it even better because it gives you a list view and it shows what kind of input the parameter takes (string, string array, int etc.)
2
u/Eijiken Aug 31 '17
I WANT THIS
But PS 5.1 here, for some reason I don't have this cmdlet.
7
u/somewhat_pragmatic Aug 30 '17
I had to get my Das Keyboard repaired under warranty for a failed backspace key. I blame the crappy default Powershell autocomplete behavior.
Thank you for posting this.
6
u/cspotcode Aug 31 '17
Check out https://github.com/cspotcode/PS-GuiCompletion for a sweet drop-down of options with filtering as you type.
Installing is easy:
(Self-promotion)
5
u/[deleted] Aug 30 '17
I usually just ctrl+c and start over but this is really cool I would have to try it out tomorrow.. thank you for sharing
3
u/SolidKnight Aug 31 '17
Today I learned that you can change key behavior in PowerShell.
I tried out MenuComplete and it will take a bit to get abused to. Makes it easier to discover commands and options though.
3
u/kisairogue Aug 31 '17
Dude, I love you.
2
u/swaddwad Aug 30 '17
This is great! Unfortunately it doesn't seem to work in the ISE (neither script pane nor terminal), know of any way to get this experience there? I like to hack away at the terminal to test things out then write it up in the script pane, would love this to work there.
2
u/existancenext Aug 31 '17
One more tip, is to use Shift+Tab to go backwards through the list