powershellcommand-line-argumentstab-completion

Using tab-completion in the shell for suggested command


*"PowerShell provides completions on input to provide hints, enable discovery, and speed up input entry. Command names, parameter names, argument values and file paths can all be completed by pressing the Tab key." Using tab-completion in the shell

I'm no stranger with using tab to complete a command, but I can't figure out how to use the hints. For example, after typing Connect-ExchangeOnline it shows me greyed out text of an argument I used recently.

Connect-ExchangeOnline -UserPrincipalName <User@Domain.com>

However, pressing tab cycles through the list of arguments for the command. I know I can use Ctrl + Space to see all the arguments, but how do I use the hinted argument it suggests?

Example

Google - I was expecting to find the answer, but I'm not quite sure how to describe this...


Solution

  • The grayed out suggestion is an inline prediction, using your command history as the prediction source (other sources can be installed).

    From Using predictors in PSReadLine:

    Pressing [the] RightArrow key accepts an inline suggestion.

    Specifically, it accepts the whole suggestion and places the cursor at the end of the line (without submitting it, so you can still edit it).

    You can customize the key bindings via Set-PSReadLineKeyHandler, by mapping a key (chord) to the following PSReadLine functions:[1]


    If you prefer to have predictions presented in a list, so that you can select an entry using the up- an down-arrow keys (which invariably uses the whole prediction):


    [1] See about_PSReadLine_Functions for a list of all functions, along with descriptions.