lib/Get-1stCompletions.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
function Get-1stCompletions([string] $WordToComplete) {
    if (-not $commands) {
        . $PSScriptRoot\..\commands.ps1
    }
    if ((-not $options) -or (-not $options['install'])) {
        . $PSScriptRoot\..\options\install.ps1
    }

    $searchBlock = { $_ -like "$WordToComplete*" }
    $completions = @()

    # Suggest commands
    $completions += $commands | Where-Object $searchBlock | ForEach-Object {
        [System.Management.Automation.CompletionResult]::new($_, $_, 'Command', $_)
    }
    # Suggest options of `install` command
    $completions += $options['install'].Keys | Where-Object $searchBlock | ForEach-Object {
        [System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterName', $_)
    }

    return $completions
}