Skip to content

Completion Context

TIP

  • Completion context is a core concept of the PSCompletions completion system.
  • Understanding it will help you better understand how the completion menu is built, and the meaning of the completion predict symbol.

What is Completion Context

Every command has its own completion context, which defines what will appear in that command's completion menu.

A completion context is made up of two parts:

  • Subcommands (next) — the next-level commands this command can switch to
  • Options (option) — the argument options this command can use

When you press the trigger key, PSCompletions builds the completion menu based on the current command's completion context.

The trigger key defaults to Tab, and can be customized via psc menu config trigger_key <Key>

Context Inheritance Rule

If a command does not have its own completion context, it will automatically use the previous command's completion context.

Take the git command as an example.

txt
PS> git
commit ~           # subcommand
switch ~           # subcommand
config ~           # subcommand
add ~              # subcommand
var                # subcommand
--version ?        # option
--help ?           # global option

After selecting config ~, it switches to config's context.

txt
PS> git config
get ~              # subcommand
set ~              # subcommand
unset ~            # subcommand
list               # subcommand
--global ?         # option
--help ?           # global option

Context Switching

  • Every completion item in the completion menu may carry a completion predict symbol.
  • It indicates how the completion context will change once you select that item.
SymbolConfig ItemContext Change
~continueSwitches to a new context.
?stayStays in the current context.
!inputStays in the current context.
May require you to manually enter a value.

After selecting switch ~, it switches to switch's context.

txt
PS> git switch
main               # branch (resolved dynamically from hooks.ps1)
develop            # branch (resolved dynamically from hooks.ps1)
--conflict ~       # option
--create !         # option (alias -c)
-c !               # option (alias --create)
--force ?          # option
--help ?           # global option

After selecting --conflict ~, it switches to --conflict's context.

txt
PS> git switch --conflict
merge              # preset value
diff3              # preset value
zdiff3             # preset value
--help ?           # global option

Released under the MIT.