forked from nverno/company-powershell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
commands.ps1
35 lines (29 loc) · 919 Bytes
/
commands.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
<#
.SYNOPSIS
Generate a list of commands and metadata for company completion.
.DESCRIPTION
Outputs data as a simple alist of form:
(("command" "commandType" "helpUri" "synopsis")
...)
.PARAMETER outfile
Path to output file, default is $PSScriptroot\commands.dat
.PARAMETER force
If non-nil overwrites outfile.
#>
param($outfile = $null,
$force = $null)
if ($outfile -eq $null) {
$outfile = [System.IO.Path]::GetFullPath("$PSScriptroot\commands.dat")
} else {
$outfile = [System.IO.Path]::GetFullPath("$outfile")
}
if (($force -eq $null) -and (Test-Path $outfile)) {
Write-Error "$outfile already exists" -ErrorAction "Stop"
}
"(" | Out-File $outfile -Encoding utf8 -Force
Get-Command |
%{("(""$($_.Name)"" ""$($_.CommandType)"" ""$($_.HelpUri)"" " +
"""$(get-help $_ | %{$_.Synopsis})"")").
Replace("`r`n", " ").Replace('\', '\\')} |
ac $outfile
")" | ac $outfile