-
Notifications
You must be signed in to change notification settings - Fork 2
/
AllHosts.ps1
117 lines (99 loc) · 3.84 KB
/
AllHosts.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
$Global:psFormatsOptions.HumanizeDate = $true
$Global:psFormatsOptions.HumanizeSize = $true
$Global:GitPromptSettings.DefaultPromptSuffix = '`n$(''>'' * ($nestedPromptLevel + 1)) '
$Global:GitPromptSettings.DefaultPromptAbbreviateHomeDirectory = $true
if(-not (Test-Path $PSScriptRoot\Cache)) {
New-Item $PSScriptRoot\Cache -ItemType Directory
}
function __UpdateCompletionCache {
$COM = Get-CimInstance -ClassName Win32_ClassicCOMClassSetting -Filter 'VersionIndependentProgId IS NOT NULL' |
foreach {
$progid = $_.VersionIndependentProgId
if($_.Caption) {
$caption = $_.Caption
} else {
$caption = $progid
}
if($_.Description) {
$description = $_.Description
} else {
$description = $progid
}
[pscustomobject]@{
ProgId = $progid
Caption = $caption
Description = $description
}
}
$Script:CompletionCache = [pscustomobject]@{
COM = $COM
}
$Script:CompletionCache | Export-Clixml $PSScriptRoot\Cache\CompletionCache.ps1xml
}
if(-not (Test-Path $PSScriptRoot\Cache\CompletionCache.ps1xml)) {
__UpdateCompletionCache
}
$Script:CompletionCache = Import-Clixml $PSScriptRoot\Cache\CompletionCache.ps1xml
Register-ArgumentCompleter -CommandName Register-ArgumentCompleter -ParameterName ParameterName -ScriptBlock {
param(
[string]$CommandName,
[string]$ParameterName,
[string]$WordToComplete,
[System.Management.Automation.Language.CommandAst]$CommandAst,
[System.Collections.IDictionary]$FakeBoundParameters
)
if(-not $FakeBoundParameters['CommandName']) {
return
}
$cmd = Get-Command $FakeBoundParameters['CommandName']
while($cmd.ResolvedCommand -ne $null) { $cmd = $cmd.ResolvedCommand }
$cmd |
foreach Parameters |
foreach Keys |
where { $_ -like "$WordToComplete*" } |
foreach {
[System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterName', $_)
}
}
Register-ArgumentCompleter -CommandName New-Object -ParameterName ComObject -ScriptBlock {
param(
[string]$CommandName,
[string]$ParameterName,
[string]$WordToComplete,
[System.Management.Automation.Language.CommandAst]$CommandAst,
[System.Collections.IDictionary]$FakeBoundParameters
)
$Script:CompletionCache.COM |
where ProgId -like "$WordToComplete*" |
foreach {
[System.Management.Automation.CompletionResult]::new($_.ProgId, $_.ProgId, 'Type', $_.Caption)
}
}
Register-ArgumentCompleter -CommandName Get-Help -ParameterName Parameter -ScriptBlock {
param(
[string]$CommandName,
[string]$ParameterName,
[string]$WordToComplete,
[System.Management.Automation.Language.CommandAst]$CommandAst,
[System.Collections.IDictionary]$FakeBoundParameters
)
try {
$cmd = Get-Command $FakeBoundParameters['Name']
while($cmd.ResolvedCommand -ne $null) { $cmd = $cmd.ResolvedCommand }
} catch [System.Management.Automation.CommandNotFoundException] {
# Most likely the result of a non-command topic (i.e. about_*), just ignore it
return
}
$commonParameters = [System.Management.Automation.Cmdlet]::CommonParameters + [System.Management.Automation.Cmdlet]::OptionalCommonParameters
$cmd.Parameters.Keys |
where { $_ -like "$WordToComplete*" -and $_ -notin $commonParameters } |
foreach {
[System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterName', $_)
}
}
$Global:PSDefaultParameterValues["Out-File:Encoding"] = 'utf8NoBOM'
# Load rg completions
. "$env:ChocolateyInstall\lib\ripgrep\tools\ripgrep-*\complete\_rg.ps1"
if (Get-Command gh -ErrorAction SilentlyContinue) {
gh completion -s powershell | Out-String | Invoke-Expression
}