Completers/PSPuTTYTheme.Name.ArgumentCompletes.1.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
$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-PSPuTTYTheme | Where-Object { $PSItem.Name -match $wordToComplete } | ForEach-Object {
    $CompletionText = '''{0}''' -f $PSItem.Name
    $ToolTip = 'PuTTY session: {0}.' -f $PSItem.Name
    $ListItemText = '{0}' -f $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'
            );
        ParameterName = 'ThemeName';
        ScriptBlock = $ScriptBlock
}

Microsoft.PowerShell.Core\Register-ArgumentCompleter @ArgumentCompleter

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

Microsoft.PowerShell.Core\Register-ArgumentCompleter @ArgumentCompleter