Completers/PSPuTTYSession.Name.ArgumentCompletes.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
$ScriptBlock = {
    <#
    .SYNOPSIS
    Auto-complete the -Name parameter value for PSPuTTY sessions.

    .NOTES
    Created by Trevor Sullivan, Founder of Art of Shell <trevor@artofshell.com>
    https://trevorsullivan.net https://artofshell.com
    #>

    param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter)

    $ItemList = Get-PSPuTTYSession | Where-Object { $PSItem.Name -match $wordToComplete } | ForEach-Object {
        $CompletionText = '''{0}''' -f $PSItem.RealName
        $ToolTip = 'PuTTY session: {0}.' -f $PSItem.Name
        $ListItemText = $PSItem.Name
        $CompletionResultType = [System.Management.Automation.CompletionResultType]::ParameterValue

        New-Object -TypeName System.Management.Automation.CompletionResult -ArgumentList @($CompletionText, $ListItemText, $CompletionResultType, $ToolTip);
    }

    return $ItemList
}

$ArgumentCompleter = @{
        CommandName = @(
            'Merge-PSPuTTYTheme'
            'Invoke-PSPuTTYSession'
            'New-PSPuTTYSession'
            'Get-PSPuTTYSession'
            );
        ParameterName = 'SessionName';
        ScriptBlock = $ScriptBlock
}

Microsoft.PowerShell.Core\Register-ArgumentCompleter @ArgumentCompleter;

$ArgumentCompleter = @{
        CommandName = @(
            'Invoke-PSPuTTYSession'
            'New-PSPuTTYSession'
            'Get-PSPuTTYSession'
            );
        ParameterName = 'Name';
        ScriptBlock = $ScriptBlock
}

Microsoft.PowerShell.Core\Register-ArgumentCompleter @ArgumentCompleter;