Hacker News new | ask | show | jobs
by bashinator 3956 days ago
The tab completion in powershell is frustrating to me. I never want to cycle through every available option (especially when many PSH commands have literally hundreds of switches). I want the tab-completion to only show options for which I've started typing the prefix. I want double-tab to print a listing of said options so that I can see them all at once. Is this possible? Right now it feels like there's a major lack of discoverability in PSH.
5 comments

> I want double-tab to print a listing of said options so that I can see them all at once. Is this possible?

In PowerShell 5 (at least in Windows 10), Ctrl-Space yields a list of matching completions. You can then use the arrow keys (ip, down, left, right) to pick one and hit enter or space to select.

It works for commands as well as for options/parameters and parameter values.

I.e. you can type get-pr[ctrl-space] and powershell responds with:

    Get-PrintConfiguration      Get-PrinterDriver           Get-PrinterProperty         Get-Process
    Get-Printer                 Get-PrinterPort             Get-PrintJob                Get-ProvisionedAppxPackage
Choose Get-Process (right,right,right,space). Now the cmdline shows

    Get-Process _
Hit [-][ctrl-space]. Powershell now shows:

    PS C:\Users\zaphod> Get-Process -Name
    Name                 IncludeUserName      FileVersionInfo      ErrorAction          ErrorVariable        OutVariable
    Id                   ComputerName         Verbose              WarningAction        WarningVariable      OutBuffer
    InputObject          Module               Debug                InformationAction    InformationVariable  PipelineVariable
Pick "Name" and hit space:

    PS C:\Users\zaphod> Get-Process -Name _
Now hit [ctrl-space] again. PowerShell now completes on running processes on the system, offering the list of all of the process names.
Yeah, that really bothered me coming from bash. I agree it's not as good from a discoverability perspective. Having said that, it's not the kind of thing that has continued to bother me over time. I've gotten used to it.
Agreed regarding the default tab completion. You might check out PSReadLine at some point - see https://github.com/lzybkr/PSReadLine. Its goal is to try to emulate readline except in PowerShell (this includes tab completion as well as emacs shortcut keys... vim shortcut keys are in the works AFAIK). It does require some additional configuration and it isn't installed by default, but I think it helps with this specific scenario quite a bit.
The usual PowerShell guru's response to your complaint is 'This is what PowerShell ISE is for'.

Personally I don't think this is elegant, but that's what I usually encounter in the wild.

For what it's worth, Windows 10 enhances the basic command host to support some more things such as nicer tab completion directly out of the box (for both traditional cmd.exe and PowerShell) without having to switch to ISE.
Hm? After typing "xyz -fo" I will get completions beginning "-fo", such as "-foo" and "-foobar", but I won't get completions that don't begin with "-fo".

But yeah, I don't like the cycling, either. I'd also prefer to get a list of the possible completions.